Calling rnorm with a vector of means

Viewed 17170

When I call rnorm passing a single value as mean, it's obvious what happens: a value is generated from Normal(10,1).

y <- rnorm(20, mean=10, sd=1)

But, I see examples of a whole vector being passed to rnorm (or rcauchy, etc..); in this case, I am not sure what the R machinery really does. For example:

a = c(10,22,33,44,5,10,30,22,100,45,97)
y <- rnorm(a, mean=a, sd=1)

Any ideas?

2 Answers

a better example:

a <- c(0,10,100)
b <- c(2,4,6)
y <- rnorm(6,a,b)
y

result

[1]  -1.2261425  10.1596462 103.3857481  -0.7260817   7.0812499  97.8964131

as you can see, for the first and fourth element of y, rnorm takes the first element of a as the mean and the first element of b as the sd.

For the second and fifth element of y, rnorm takes the second element of a as the mean and the second element of b as the sd.

For the third and sixth element of y, rnorm takes the third element of a as the mean and the third element of b as the sd.

you can experiment with diferent number in the first argument of rnorm to see what is happening

For example, what is happening if you use 5 instead 6 as the first argument in calling rnorm?

Related