Re: [R] Converting data frame into multidimensional array

2011-10-21 Thread Luk Arbuckle
Thank-you for the replies. I would say that the function xtabs() is the simplest method. And thanks for pointing out that a table is also an array, as I clearly wasn't aware of that. On 2011-10-21, at 19:07, Gabor Grothendieck wrote: > On Fri, Oct 21, 2011 at 7:04 PM, Gabor Grothendieck > wrot

Re: [R] Converting data frame into multidimensional array

2011-10-21 Thread Gabor Grothendieck
On Fri, Oct 21, 2011 at 7:04 PM, Gabor Grothendieck wrote: > On Fri, Oct 21, 2011 at 4:15 PM, Luk Arbuckle wrote: >> Consider the following data frame >> >> X <- data.frame(Titanic) >> >> Does anyone know of an easy way to convert X into a multidimensional >> array?  Example that doesn't work >>

Re: [R] Converting data frame into multidimensional array

2011-10-21 Thread Gabor Grothendieck
On Fri, Oct 21, 2011 at 4:15 PM, Luk Arbuckle wrote: > Consider the following data frame > > X <- data.frame(Titanic) > > Does anyone know of an easy way to convert X into a multidimensional > array?  Example that doesn't work > > X <- as.array(X, dim=c(4,2,2,2)) > > To do what I need, X needs to

Re: [R] Converting data frame into multidimensional array

2011-10-21 Thread Richard M. Heiberger
You are probably looking for the structable and related functions in the vcd package. Be sure to read the vignettes library(vcd) X <- data.frame(Titanic) XS <- structable(~Class+Sex+Age+Survived, data=X) as.table(XS) is.array(XS) Rich On Fri, Oct 21, 2011 at 5:56 PM, Luk Arbuckle wrote: > I nee

Re: [R] Converting data frame into multidimensional array

2011-10-21 Thread Luk Arbuckle
I need something that will work with any, possibly very large, data frame. This dataset is only a very small example. On 2011-10-21, at 17:31, David L Carlson wrote: > How about? > >> x <- array(Titanic, dim=c(4,2,2,2)) >> str(x> > num [1:4, 1:2, 1:2, 1:2] 0 0 35 0 0 0 17 0 118 154 ... > >

Re: [R] Converting data frame into multidimensional array

2011-10-21 Thread David L Carlson
How about? > x <- array(Titanic, dim=c(4,2,2,2)) > str(x> num [1:4, 1:2, 1:2, 1:2] 0 0 35 0 0 0 17 0 118 154 ... -- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352 -Original Message- From