[R] Combining many dataframes from listings of objects?

Derek Eder Derek.Eder at neuro.gu.se
Wed May 15 11:42:06 CEST 2002


I want to combine (rbind) many dataframes into a single data frame, but "automatically" specifying the names of the dataframes as listing of object names.

E.g., combine these 18 df objects into one big df using something conceptually like this :   

rbind(objects(pattern="*.df"))  

 ...

> objects(pattern="*.df")
 [1] "BA.Nt1.nREM.APNEA.MIXED.bp.df"       "BA.Nt1.nREM.APNEA.OBSTRUCTIVE.bp.df"
 [3] "BA.Nt1.nREM.HYPOPNEA.bp.df"          "BA.Nt1.REM.HYPOPNEA.bp.df"          
 [5] "BA.Nt2.nREM.APNEA.MIXED.bp.df"       "BA.Nt2.nREM.APNEA.OBSTRUCTIVE.bp.df"
 [7] "BA.Nt2.nREM.HYPOPNEA.bp.df"          "BA.Nt2.REM.APNEA.OBSTRUCTIVE.bp.df" 
 [9] "BA.Nt2.REM.HYPOPNEA.bp.df"           "BF.Nt1.nREM.APNEA.MIXED.bp.df"



By the way in S. I used to do this by creating a large empty target dataframe and then
looping through the list of objects, write each one into the target.  This is failing in R:

> target_as.data.frame(matrix(data=NA,nrow=8,ncol=14))
> target[1:4,]__c("a","b","c","d")

> Warning messages:
1: invalid factor level, NAs generated in: "[<-.factor"(*tmp*, iseq, value = vjj) 
2: invalid factor level, NAs generated in: "[<-.factor"(*tmp*, iseq, value = vjj) 
3: invalid factor level, NAs generated in: "[<-.factor"(*tmp*, iseq, value = vjj) 
4: invalid factor level, NAs generated in: "[<-.factor"(*tmp*, iseq, value = vjj) 
. . .


Thank you
 

Derek N. Eder
Göteborgs Universitet
Institutionen för klinisk neurovetenskap - psykiatri
Sahlgrenska universitetssjukhuset SS/SU
Blå straket 17b
SE 413 45  Göteborg
Sverige
Tlf. +46 (031) 34  2-6139  (office)
Tlf. +46 (031) 34 2-1283  (laboratory)
Tlf. +46 0709 / 7 2-1283 (mobil)
Fax. +46 (031) 82 81 63 
derek.eder at neuro.gu.se


Gothenburg University
Institute of Clinical Neuroscience,
Section for Psychiatry
Salhgrenska Hospital  SU/SS
SE 413 45  Göteborg
Sweden


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