Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RStudio- How to produce inline r results?

For example, I want to be able to do "The result is ...." and have the ... be replaced with the r output. I considered using "cat", but it is not as neat.

Here is another example of what I wish to achieve.

```{r, echo=FALSE}
x <- rnorm(100, 0, 2)
a<- mean(x)
```

The result of running a random number generator from a normal distribution with mean 0 and sd 2 has a mean of (somehow output variable a).

Any suggestions?

like image 890
Will Avatar asked Dec 20 '25 23:12

Will


1 Answers

Use backticks with a leading r, for instance:

2 + 2 = `r 2+2`.

or in your case,

the result is `r a`
like image 107
Jonathan Avatar answered Dec 23 '25 14:12

Jonathan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!