Skip to content
Prev 207167 / 398502 Next

Create a multi dimensional array from a data frame

On Jan 21, 2010, at 6:06 PM, LCOG1 wrote:

            
H <- array(c(h1i1a1, h1i1a2, h1i1a3, h1i2a1, h1i2a2, h1i2a3, h1i3a1,  
h1i3a2, h1i3a3, h1i4a1, h1i4a2, h1i4a3, h2i1a1, h2i1a2, h2i1a3,  
h2i2a1, h2i2a2, h2i2a3, h2i3a1, h2i3a2, h2i3a3, h2i4a1, h2i4a2,  
h2i4a3, h3i1a1, h3i1a2, h3i1a3, h3i2a1, h3i2a2, h3i2a3, h3i3a1,  
h3i3a2, h3i3a3), c(5,3,3,3) , dimnames=list(NULL, paste("i", 1:3,  
sep=""), paste("h", 1:3, sep=""),paste("a", 1:3, sep="") ))
  H

Would have been a lot easier to do this:
H < array( sample(1:20, 5*3*3*3, replace=TRUE), c(5,3,3,3) )

You can rearrange the names and dimensions to suit your tastes.
David Winsemius, MD
Heritage Laboratories
West Hartford, CT