Dear all, I would like to generate 500 matrices of 20 numbers from standard normal distribution with names x1,x2,x3,….x500. I tried with loop for, but I don’t know how to name matices : for (i in 1:500) { x[[i]] <- matrix(rnorm(20), 4) } Any suggestion? Thanks, Blaž [[alternative HTML version deleted]]
What about this? B <- 500 X <- matrix(rnorm(B*20), ncol = B) colnames(X) <- paste('x', 1:B, sep = "") head(X) Thus, each column correspond to a sample of 20 numbers from a standard normal distribution. HTH, Jorge.- On Thu, Feb 9, 2012 at 8:38 AM, Blaz Simcic <> wrote:> Dear all, > I would like to generate 500 matrices of 20 numbers from > standard normal distribution with names x1,x2,x3,….x500. > I tried with loop for, but I don’t know how to name matices : > for (i in 1:500) { > x[[i]] <- matrix(rnorm(20), 4) } > Any suggestion? > Thanks, Blaž > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >[[alternative HTML version deleted]]
On Feb 9, 2012, at 8:38 AM, Blaz Simcic wrote:> Dear all, > I would like to generate 500 matrices of 20 numbers from > standard normal distribution with names x1,x2,x3,?.x500. > I tried with loop for, but I don?t know how to name matices : > for (i in 1:500) { > x[[i]] <- matrix(rnorm(20), 4) } > Any suggestion?Don't do it that way. Create an array-object instead. > x <- array(NA, dim=c(4,5,500) ) > x[] <- rnorm(4*5*500) > str(x) num [1:4, 1:5, 1:500] -0.721 0.896 -1.432 0.386 -1.111 ... > dimnames(x)[[3]] <- paste("x", 1:500, sep="") > str(x) num [1:4, 1:5, 1:500] -0.721 0.896 -1.432 0.386 -1.111 ... - attr(*, "dimnames")=List of 3 ..$ : NULL ..$ : NULL ..$ : chr [1:500] "x1" "x2" "x3" "x4" ... -- David Winsemius, MD West Hartford, CT
Apparently Analagous Threads
- Not missing at random
- Principal Component Analysis
- `samba-tool dbcheck --cross-ncs --fix` fails: governsID already exists as an attributeId or governsId
- Samba3 in W2k AD, W98 clients need password for Samba share
- `samba-tool dbcheck --cross-ncs --fix` fails: governsID already exists as an attributeId or governsId