RDJ RDJ - 1 month ago 18
R Question

R: using `rnorm` to create vectors with specific variance

I want to create two different vectors of data which are normal distributions. One which has a a mean value of 0 and variance of 1; one which has a mean value of 0 and variance of 0.25.

Can this be done with

rnorm
? If not what is the best way to do this in R?

Answer

Of course. Type ?rnorm into the console to learn more about it. I'm assuming you want vectors with 100 numbers, but just change n if you want.

vector1 = rnorm(n = 100, mean = 0, sd = sqrt(1))
vector2 = rnorm(n = 100, mean = 0, sd = sqrt(0.25))