[R] indexing data.frames

John Fox jfox at mcmaster.ca
Sun Mar 3 23:29:14 CET 2002


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list