[R] Add a dim to an array

Patrick Hausmann c18g at uni-bremen.de
Sat Jun 2 17:17:36 CEST 2012


Dear list,

I'm trying to add a new dim to a multidimensional array. My array looks 
like this

a1 <- array(1:8, c(2, 2, 2))
dimnames(a1) <- list(A = c("A1", "A2"),
                      B = c("B1", "B2"),
                      D = c("D1", "D2"))

I would like to add a new dim 'group' with the value "low". Right now 
I'm using this, but I think are better ways...

a2 <- as.data.frame(as.table(a1))
a2$group <- "low"
a2 <- xtabs(Freq ~ A + B + D + group, data = a2)
a2

Thanks for any help!
Patrick



More information about the R-help mailing list