3

How can I get R chunk code to produce the same number of digits as r inline code in RStudio RMarkdown file?

For example:

```{r}
x=1:30
sigma.sq=sum((x-mean(x))^2)/30
sigma.sq    
```

Thus, $\sigma^2=`r sigma.sq`$.

The chunk produces the number 74.92, but the inline code produces the number 74.9167. I'd like both to be the same.

Suggestions?

D.

P.S. Here's a screen shot of what the above code produces.

enter image description here

4

1 回答 1

2

round() 函数给你一个答案。例如,R Markdown 中的以下内联代码将显示对象编号的第二个小数位。

`r round(sigma.sq, 2)`
于 2017-03-23T01:16:35.167 回答