Generate matrix with iid normal random variables using R
To create an N
by M
matrix of iid normal random variables type this:
matrix( rnorm(N*M,mean=0,sd=1), N, M)
tweak the mean and standard deviation as desired.
let mu
be a vector of means and sigma
a vector of standard devs
mu<-1:10sigma<-10:1sample.size<-100norm.mat<-mapply(function(x,y){rnorm(x,y,n=sample.size)},x=mu,y=sigma)
would produce a matrix with columns holding the relevant samples
You can use:
replicate(NumbOfColumns,rnorm(NumbOfLines))
You can replace rnorm
with other distribution function, for example runif
, to generate matrices with other distributions.