[R] How to make an array of data.frames?

Gabor Grothendieck ggrothendieck at gmail.com
Sun Aug 26 18:36:30 CEST 2007


That gives you a list of data frames. An array is a vector with a dim
attribute to to make it into an array add the appropriate dim attirbute.

If x is the list we created before then:

dim(x) <- 2

gives us an array of length 2 each of which has a list of 3 elements
or

dim(x) <- 1:2

gives a 1x2 array

or

y <- list(DF1, DF2, DF3, df1, df2, df3)
dim(y) <- 3:2

gives a 3x2 array so you can write y[[1,2]] for example.
etc.

On 8/26/07, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> Is this what you want:
>
> DF1 <- DF2 <- DF3 <- df1 <- df2 <- df3 <- head(iris)
> list(a = list(DF1, DF2, DF3), b = list(df1, df2, df3))
>
> or
>
> x <- list()
> x$a <- list(DF1, DF2, DF3)
> x$b <- list(df1, df2, df3)
>
>
> On 8/26/07, Werner Wernersen <pensterfuzzer at yahoo.de> wrote:
> > Hi,
> >
> > I am still struggling with the data structures in R. I
> > know how it works in C++ but how can I get such a
> > structure in R?
> >
> > Here is what I want:
> > x["a"]$dataframe1
> > x["a"]$dataframe2
> > x["a"]$dataframe3
> > x["b"]$dataframe1
> > x["b"]$dataframe2
> > x["b"]$dataframe3
> > x["c"]$dataframe1
> > x["c"]$dataframe2
> > x["c"]$dataframe3
> >
> > And it would be nice if I could fill in "objects" a,
> > b, c one at a time successively.
> >
> > What is the easiest way to get such a data structure?
> > It would be great if someone could give me some help
> > with this.
> >
> > Many thanks and kind regards,
> >  Werner
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch 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