My question is straightforward: I have generated this type of object in R, that looks like a data frame, but is actually an array.
> confidence
, , 1
[,1] [,2]
2.5% 16.98751 -0.03834785
97.5% 17.58275 -0.01476014
, , 2
[,1] [,2]
2.5% 18.69040 -0.06682464
97.5% 19.63179 -0.03040943
, , 3
[,1] [,2]
2.5% 20.41596 -0.09509432
97.5% 21.58752 -0.05110339
> class(confidence)
[1] "array"
I am looking for a way to export it in a useful format, for example to work on it with excel. I am open to any type of object conversion if needed.
Thank you for your help!
CodePudding user response:
1) adply This will convert a 3d array to a data frame and then you can use write.csv and import it into Excel or transfer it using other R packages.
# test input
a <- array(1:24, 2:4, dimnames =
list(dim1 = c("a", "b"), dim2 = c("A", "B", "C"), dim3 = 1:4))
plyr::adply(a, 1:2)
giving:
dim1 dim2 1 2 3 4
1 a A 1 7 13 19
2 b A 2 8 14 20
3 a B 3 9 15 21
4 b B 4 10 16 22
5 a C 5 11 17 23
6 b C 6 12 18 24
2) ftable Another way is to use ftable and ftable2df. The latter is defined in this SO post: