Calling rnorm with a vector of means

The number of random numbers rnorm generates equals the length of a. From ?rnorm:

n: number of observations. If ‘length(n) > 1’, the length is taken to be the number required.

To see what is happening when a is passed to the mean argument, it's easier if we change the example:

a = c(0, 10, 100)
y = rnorm(a, mean=a, sd=1)
[1] -0.4853138  9.3630421 99.7536461

So we generate length(a) random numbers with mean a[i].


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?