I have a lot of csv files that I want to read and then merge with a larger file (each file merged individually). So I wrote this function to read the files (works):
read <- function(x) {
read.csv(paste("StringCount_Length=", x, ".csv", sep = ""), header=TRUE, sep=",")
}
Now I want to loop through the files, read and merge them. However, the merge does not work giving me this error message:
Error in fix.by(by.x, x) : 'by' must specify a uniquely valid column
I do not get the error if I put a specific file in the merge command so my mistake must be there but I can't quite see where I went wrong. Would be grateful for any help or advice!
for (x in c(2:5)) {
assign(paste("data", x, sep=""), read(x))
assign(paste("data_total_",x, sep=""), merge(paste("data", x, sep=""), data_old, by="Subject"))
}