What does rnorm return in R when the sd argument contains a vector?

What the following code does:

rnorm(10, mean=2, sd=1:10) 

The first number from N (2,1)

The second number, if from N (2,2)

The third number from N (2,3)

etc...?

+4
source share
1 answer

The first argument tells R how many random variations you want to return. In this case, it will return you 10 values. These values ​​will be taken from normal distributions with an average value of 2. In addition, all 10 values ​​will be taken from distributions with different standard deviations, the first with SD = 1, the second with 2, ..., 10th SD = 10, Perhaps , you need to understand that R is vectorized by nature. That is, there is no such thing as a scalar, only a vector of length = 1. (I understand that this does not make much sense in pure mathematics, but this happens in computer science.) As a result, the arguments are often “processed”, so that they will correspond the length of the longest vector, i.e. you get a vector of 10 means, each of which is 2, to match your 10 SD vector. NTN.

+9
source

Source: https://habr.com/ru/post/1411676/


All Articles