+4 votes
in Programming Languages by (5.2k points)
I want to generate n numbers from a normal distribution. What R function should I use for it?

1 Answer

0 votes
by (33.0k points)

You can use the rnorm() function to generate numbers from a normal distribution. The default mean and the standard deviation is 0 and 1 respectively. However, you can specify mean and standard deviation as parameters.

> k=10
> rnorm(k)
 [1]  0.7541563 -1.1518478  1.7277658 -0.1603675 -1.5974576 -1.6219231  2.0559305  0.4058585  0.9727986 -0.8324257
> rnorm(k, mean = 4, sd=5)
 [1]  3.185434  2.815246  4.273128  8.792573  9.658461 -5.639771  4.658557  2.802040  6.544981  4.919186

Related questions

+3 votes
1 answer
+4 votes
1 answer
+4 votes
1 answer
...