Dear R-help, I have a series of data.frames (i1,i2,...,in) all containing the same number of items, but dissimilar content. I would like to instal them in another data.frame, say index, so that I can access their items with index[i,j]. No matter how I try to set index up, its subframes cannot be indexed, because they all have the row number of 1. What am I doing wrong? (I get the same result with lists, a data.frame of lists, or a list of data.frames) Alternatively, does R contain an equivalent to the INDIRECT function found in spreadsheets, so that instead of doing, say, edit(i6), I could get instead edit(the vector named by the content of i6)? Thank you in advance for your help graham lawrence _________________________________________________________________ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
graham lawrence wrote:> > Dear R-help, > > I have a series of data.frames (i1,i2,...,in) all containing the same number > of items, but dissimilar content. I would like to instal them in another > data.frame, say index, so that I can access their items with index[i,j]. > > No matter how I try to set index up, its subframes cannot be indexed, > because they all have the row number of 1. What am I doing wrong? (I get > the same result with lists, a data.frame of lists, or a list of data.frames) > > Alternatively, does R contain an equivalent to the INDIRECT function found > in spreadsheets, so that instead of doing, say, edit(i6), I could get > instead edit(the vector named by the content of i6)?I'm not quite sure if I understand your question correctly. Here an example for indexing data.frames in a list: x <- data.frame(a1=1:10, b1=2:11) y <- data.frame(a2=11:20, b2=12:21) L <- list(x=x, y=y) L # two data.frames in a list. L[[1]][[1]][1] # first list element, first col, first item L[[1]][[2]][3] # first list element, second col, third item L[[2]][[2]][10] # second list element, second col, last item Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear Graham, At 11:43 AM 3/3/2002 -0800, graham lawrence wrote:>I have a series of data.frames (i1,i2,...,in) all containing the same >number of items, but dissimilar content. I would like to instal them in >another data.frame, say index, so that I can access their items with >index[i,j]. > >No matter how I try to set index up, its subframes cannot be indexed, >because they all have the row number of 1. What am I doing wrong? (I get >the same result with lists, a data.frame of lists, or a list of data.frames) > >Alternatively, does R contain an equivalent to the INDIRECT function found >in spreadsheets, so that instead of doing, say, edit(i6), I could get >instead edit(the vector named by the content of i6)?If I understand correctly what you're trying to do, you want to index variables in a collection of data frames. I think that the natural way to do this in R is to use a list of data frames; e.g., using your names, index <- list(i1, i2, etc.). You could then access the second variable in the first data frame of the list as index[[1]][[2]]. Granted, the subscripts aren't of the form [1, 2], nor does this data structure require that the individual data frames be similar, but perhaps this will do what you need. I hope that this helps, John ----------------------------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: jfox at mcmaster.ca phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox ----------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._