I’m trying to use xtable for 3-dimensional array. My minimal example is
Test <-
structure(1:8, .Dim = c(2L, 2L, 2L), .Dimnames = list(c("A1",
"A2"), c("B1", "B2"), c("C1", "C2")))
library(plyr)
library(xtable)
a_ply(.data=Test, .margins=3, function(i) {
xtable(x = Test[, , i])
}
)
This produces the following error:
Error in xtable(x = Test[, , i]) : subscript out of bounds
I’d appreciate if you give me some pointers to resolve this problem. Thanks in advance.
a_plydoesn’t return anything so hopefully your function saves these or something along those lines. the i you’re passing to the function is the subset of your array based on the margins you provide. so you’re sending it the 2×2 array C1 then the 2×2 array C2:so indexing into your
Testarray withidoesn’t make sense.why not just:
or using plyr:
For knitr: