[R] Automation of c()

Uwe Ligges ligges at statistik.uni-dortmund.de
Sat Apr 10 11:39:52 CEST 2004



Miha STAUT wrote:
> 
> Hi,
> 
> I have around 300 files with the x, y and z coordinates of a DEM that I
> would like to join in a single data frame object. I know how to automate the
> import of the 300 data frames.
> 
> in Bash
> ls > names
> 
> in R
> names<-scan(names...)
> With rep() and data.frame() construct a series of read.table() commands,
> which you write to a file and execute them with source().

It's simpler, all can be done within R:

names <- list.files()
dat <- read.table(names[1])
for(i in names[-1])
    dat <- rbind(dat, read.table(i))

  
This example is quite ugly and maybe slow (I guess for huge data frames,
the solution presented by Christophe Pallier will be faster), in
particular the rbind() calls. If all data.frames have the same nrow(),
one can improve quite easily...

Uwe Ligges

 
> I do not know however how to automate the combination of the e.g. x vectors
> from all imported data frames in a single vector avoiding the manual writing
> of all the imported data frame names.
> 
> Thanks in advance, Miha




More information about the R-help mailing list