我在将40个不同的csv文件合并为一个时遇到了问题。它们都具有相同的变量var 1 var2和id。但是当我将它们组合在一起时,我得到2列,其中所有变量都在一列中。我不确定为什么会这样,这是我的代码:
#Combine all files into one file
final = list.files(pattern="*.csv")
for (i in 1:length(final)) {
assign(final[i], read.csv(final[i]))
}
allfiles = lapply(final,read.delim)
#Have to install plyr and reshape packages for rbind.fill
#Bind matrices by row and fill in missing columns with NA
FilledFiles <- do.call(rbind.fill, allfiles)
#Save combined dataset as Final_Data
write.csv(FilledFiles, file="Final_Data.csv")