【问题标题】:Copy r output to the report when writing the report编写报告时将r输出复制到报告中
【发布时间】:2017-02-15 23:36:54
【问题描述】:

如何将r输出直接包含(复制)到kintr(rmarkdown)中的报告中?

我在某些段落中使用 knitr (rmarkdown) 编写报告,我需要提及 p 值。因此,如果将 r 输出直接包含在段落中,我不需要在数据集更改时再次更改该值。你能建议我这样做吗?

【问题讨论】:

    标签: r knitr r-markdown


    【解决方案1】:

    您可以使用内联调用来报告先前分析的值。例如:

    ```{r}
    y <- 5
    ```
    
    The value of y that we set was `r y`.
    

    这应该打印出来:

    我们设置的 y 值为 5。

    所以对于线性模型,您只需使用类似

    ```{r}
    y <- runif(100)
    x <- rnorm(100)
    lmyx <- lm(y~x)
    sum.lmyx <- summary(lmyx)
    ```
    
    The adjusted R-squared of the best fit linear model was `r sum.lmyx$adj.r.squared`
    

    【讨论】:

      猜你喜欢
      • 2022-08-09
      • 1970-01-01
      • 1970-01-01
      • 2013-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-06
      • 1970-01-01
      相关资源
      最近更新 更多