[R] Using reduce to merge multiple files
Kate Ignatius
kate.ignatius at gmail.com
Thu Jun 12 19:16:46 CEST 2014
I have a list of files that I have called like so:
main_dir <- '/path/to/files/'
directories <- list.files(main_dir, pattern = '[[:alnum:]]', full.names=T)
filenames <- list.files(file.path(directories,"/tmpdir/"), pattern =
'[[:alnum:][:punct:]]_eat.txt+$', recursive = TRUE, full.names=T)
This lists around 35 Files. Each has multiple columns but they all
have three columns in common: Burger, Stall and Cost which I want to
merge on using:
m1 <- Reduce(function(a, b) { merge(a, b,
by=c("Burger",Stall","Cost")) }, filenames)
However, I get the error:
Error in fix.by(by.x, x) : 'by' must specify uniquely valid columns
Is there something that I have obviously overlooked here?
Thanks in advance!
More information about the R-help
mailing list