[R] Chopping a two column data frame by rows into a three dimensional array.

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Tue Oct 16 03:33:49 CEST 2012


aperm(array(dat,c(10,10,2)),c(1,3,2))
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

Hans Thompson <hans.thompson1 at gmail.com> wrote:

>If I have a two column data frame like:
>
>> dat <- cbind("x"=c(1:100),"y"=c(100:1))
>
>How can I create an array that splits every ten rows of that data frame
>into a third dimension of an array so that:
>
>> newarray[,,1]
>
>,,1
>
>x   y
>1   100
>2   99
>3   98
>...   ...
>10  91
>
>
>,,2
>
>x    y
>11  90
>12  89
>...   ...
>
>
>...
>
>Thanks.
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>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