user423805 - 5 days ago 4x

R Question

When I call

`rnorm`

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

But, I see examples of a whole vector being passed to

`rnorm`

`rcauchy`

`a = c(10,22,33,44,5,10,30,22,100,45,97)`

y <- rnorm(a, mean=a, sd=1)

Any ideas?

Answer

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]`

.

Source (Stackoverflow)

Comments