I'm trying to merge many csv files in R. They all share a common column and the merge command works just fine when I manually type in the name of two of the csv files. However, I have too many files to type all the names out every time I need to do this.
This works just fine:
test <- merge(quant_dysmorph_data.csv, srs_adult.csv, by = "individual", all
= TRUE)
I can make something similar as input for the merge command that looks fine too:
cat(ls(pattern = ".csv"), sep = ",")
Returns: bapq.csv,bapq_raw.csv,bapq_recode.csv,fhi_informant.csv,fhi_interviewer.csv,fhi_subject.csv,quant_dysmorph_data.csv,srs_adult.csv (and so on and so on. Sorry, the comment box won't format it as output correctly...)
However, when I use this as input for the merge command I get an error:
x <- merge(cat(ls(pattern = ".csv"), sep = ","), by = "individual", all =
TRUE)
Returns:
Error in as.data.frame(y) : argument "y" is missing, with no default
7.as.data.frame(y)
6.as.data.frame(y)
5.nrow(y <- as.data.frame(y))
4.merge.data.frame(as.data.frame(x), as.data.frame(y), ...)
3.merge(as.data.frame(x), as.data.frame(y), ...)
2.merge.default(cat(ls(pattern = ".csv"), sep = ","), by = "individual", all
= TRUE)
1.merge(cat(ls(pattern = ".csv"), sep = ","), by = "individual", all = TRUE)
Thanks in advance for your help.