对于R,如何对列表中未知数量的项进行行绑定?
我是R的新手。我有许多csv文件要附加到单个csv文件中 我的以下代码中存在以下问题:对于R,如何对列表中未知数量的项进行行绑定?,r,csv,dplyr,R,Csv,Dplyr,我是R的新手。我有许多csv文件要附加到单个csv文件中 我的以下代码中存在以下问题: 第三行之后 read.table中出现错误(file=file,header=header,sep=sep,quote=quote,: 缺少参数“file”,没有默认值** 我不知道文件夹中要行绑定的文件数。那么如何修改这行代码以行绑定未知数量的文件? 绑定行(表[1]、表[2]、表[3]) 谢谢大家! library(dplyr) files <- list.files(path = "
library(dplyr)
files <- list.files(path = "C:/Users/...",pattern="*.csv", full.names = T)
tables <- lapply(files, read.csv(header=False))
merged <- bind_rows(tables [1], tables [2], tables[3])
write.csv(merged, file = "C:/.../files_merged.csv", row.names = FALSE)
库(dplyr)
文件代码中存在一些语法问题。请尝试以下操作:
files <- list.files(path = "C:/Users/...",pattern="*.csv", full.names = T)
tables <- do.call(rbind, lapply(files, read.csv, header=FALSE))
#A bit shorter
#tables <- purrr::map_df(files, read.csv, header=FALSE)
write.csv(tables, file = "C:/.../files_merged.csv", row.names = FALSE)
filesbind\u rows
接受一个列表,合并