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.
round() function gives you an answer. For example, the below inline code in R Markdown would display the second decimal place of the number of the object.
`r round(sigma.sq, 2)`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With