[R] Combining multiple datasets

Alison Macalady ali at kmhome.org
Fri Aug 22 04:42:25 CEST 2008


Hi,
I've tried to figure this out using Intro to R and help(), to no avail 
- I am new at this.

I'm trying to write a script that will read multiple files from a 
directory and then merge them into a single new data frame.
The original data are in a tree-ring specific format, and so I've first 
used a function (read.rwl) from the dplR package to read each file, 
translate each into a more intuitive time series format, and then put 
each new data frame into a single object, demo.Rwl:

 >demo.Rwl <- list.files(pattern=".RWL$"); for(i in demo.Rwl) { x <- 
read.rwl(i, header=TRUE); assign(print(i, quote=FALSE), x)}

This part seems to work.  Now, I want to be able to put all of the 
individual data frames contained in demo.Rwl into a single data frame, 
merging by rows (rows are calendar years in the time series). I think I 
know how to do this by typing each data set name into a merge:

 >merge(x,y..., by.x=0, all=TRUE )

However, I'd like to be able to script something that will save me the 
time of typing in all of the individual data set names, as I will be 
repeating this operation many times with many different numbers of 
original input files. Is there a way to code a merge such that every 
individual data frame contained in demo.Rwl (a different number every 
time) gets combined into a single data set?

Thanks for the help!

Ali



More information about the R-help mailing list