[R] data.frame subsetting

Hecht Michael, F+E/ST Michael.Hecht at dillinger.biz
Mon Sep 29 16:20:47 CEST 2003


Hi,
 
I think I have the same problem. The following works
 
> aa<-data.frame(1:10)
> ab<-data.frame(1:12)
> ba<-data.frame(1:14)
> bb<-data.frame(1:16)
> xa<-data.frame()
> xa$aa<-aa
> xa$ab<-ab
> xb<-data.frame()
> xb$ba<-ba
> xb$bb<-bb
> xx<-data.frame()
> xx$xa<-xa
> xx$xb<-xb
> summary(xx)
 xa.aa.X1.10      xa.ab.X1.12     xb.ba.X1.14      xb.bb.X1.16    
 Min.   : 1.00    Min.   : 1.00   Min.   : 1.00    Min.   : 1.00  
 1st Qu.: 3.25    1st Qu.: 3.75   1st Qu.: 4.25    1st Qu.: 4.75  
 Median : 5.50    Median : 6.50   Median : 7.50    Median : 8.50  
 Mean   : 5.50    Mean   : 6.50   Mean   : 7.50    Mean   : 8.50  
 3rd Qu.: 7.75    3rd Qu.: 9.25   3rd Qu.:10.75    3rd Qu.:12.25  
 Max.   :10.00    Max.   :12.00   Max.   :14.00    Max.   :16.00  
> is.data.frame(xx)
[1] TRUE
> is.data.frame(xx$xa)
[1] TRUE
> is.data.frame(xx$xb)
[1] TRUE
> is.data.frame(xx$xa$aa)
[1] TRUE

this works not:
 
> ya<-data.frame()
> ya[["aa"]]<-aa
Error in "[[<-.data.frame"(*tmp*, "aa", value = aa) : 
        replacement has 10 rows, data has 0
 
So I also would like produce a sub-data.frame, maybe by this way
 
> subframename<-"subset 1"
> mydataframe[[subframename]] <- mysubframe1
> subframename<-"subset 2"
> mydataframe[[subframename]] <- mysubframe2
> ...
 
is this possible?? Normally I would like to use a loop to do this!!




More information about the R-help mailing list