2
votes

I know that if I want to generate for example 120 numbers from normal distribution with mean 30 and standard deviation 20 i can do it by command :

x=rnorm(120,30,20) 

But what if I want to generate 100 times 120 numbers from above normal distribution ?

Do we have in R any function to do this directly ?

1
See help("replicate") - duckmayr
most efficient to do something like matrix(rnorm(100*120,30,20),nrow=100) - Ben Bolker
rnorm(120*100, 30,20) will do that - but I suspect your question should say you want 100 sets of random numbers in order to something with each set. So Ben Bolker's answer will put each set into each row of a matrix. What do you want to do with your random numbers? - Spacedman

1 Answers

1
votes

As proposed by @duckmayr

replicate(100, rnorm(120, 30, 20), simplify = TRUE) # if you want to generate a matrix

replicate(100, rnorm(120, 30, 20), simplify = FALSE) # if you want to generate a list