Skip to content

generate matrices

4 messages · Blaz Simcic, Jorge I Velez, David Winsemius +1 more

#
On Feb 9, 2012, at 8:38 AM, Blaz Simcic wrote:

            
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" ...
#
Inline below.

-- Bert
On Thu, Feb 9, 2012 at 8:59 AM, David Winsemius <dwinsemius at comcast.net> wrote:
Inefficient. Do it in one go:

x <- array(rnorm(20*500), dim = c(4,5,500))