[R] Lining up x-y datasets based on values of x

Marc Schwartz marc_schwartz at comcast.net
Thu Feb 1 22:20:50 CET 2007


On Thu, 2007-02-01 at 15:45 -0500, Christos Hatzis wrote:
> Thanks Marc and Phil.
> 
> My dataset actually consists of 50+ individual files, so I will have to do
> this one column at a time in a loop...
> I might look into SQL and outer joints as an alternative to avoid looping.
> 
> Thanks again.
> -Christos 

If the files conform to some naming convention and/or are all located in
a common sub-directory, you can use list.files() to get the file names
into a vector.  If not, you could use file.choose() interactively.

Then use either a for() loop or sapply() to loop over the filenames,
read them in to data frames using read.table() and merge them together
in the same loop.

When it comes to basic data manipulation like this, loops are not a bad
thing. The overhead of a loop is typically outweighed by the file I/O
and related considerations.

HTH,

Marc



More information about the R-help mailing list