[R] How to "flatten" a multidimensional array into a dataframe?

baptiste auguie baptiste.auguie at googlemail.com
Thu Apr 19 23:01:35 CEST 2012


library(plyr)
adply(my.array,1:3)

HTH,

baptiste

On 20 April 2012 08:46, Emmanuel Levy <emmanuel.levy at gmail.com> wrote:
> Hi,
>
> I have a three dimensional array, e.g.,
>
> my.array = array(0, dim=c(2,3,4), dimnames=list( d1=c("A1","A2"),
> d2=c("B1","B2","B3"), d3=c("C1","C2","C3","C4")) )
>
> what I would like to get is then a dataframe:
>
> d1 d2 d3  value
> A1 B1 C1 0
> A2 B1 C1 0
> .
> .
> .
> A2 B3 C4 0
>
> I'm sure there is one function to do this transformation, I just don't
> know which one.
>
> Thanks for your help,
>
> Emmanuel
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list