rstatisticsdata-generation

standard deviation in rnorm() in r


Just wondering what sd=1:10 really means in rnorm function (never seen this before) u <- rnorm(mean = 0, sd = 1:10, n = 10). Is there any simple way to check each value of sd using r command?


Solution

  • If you pass a vector as sd, each value will be applied to each simulation until your n is reached, for example:

    rnorm(mean = 0, sd = c(0,100000), n = 5)
     0.00 116963.06      0.00  25354.82      0.00
    

    So the first value is from a normal distribution with mean = 0 and standard deviation = 0, the second value has a sd of 100.000, the third value has a sd of 0,...

    In your example each value will be simulated from a normal distribution with a different sd, going from 1 to 10.