如何附加2个以上的文件路径(与append()相同)

问题描述 投票:0回答:1

目前的方法太多了,无法逐一粘贴每个列表。

# CURRENT METHOD
FL_PATH_1 <- list.files(path = "~/MY_FOLDER_1"),
                              pattern = "*.CSV",full.name = T)
FL_PATH_2 <- list.files(path = "~/MY_FOLDER_2"),
                              pattern = "*.CSV",full.name = T)
FL_PATH_3 <- list.files(path = "~/MY_FOLDER_3"),
                              pattern = "*.CSV",full.name = T)

FL_PATH_BP_A <- append(FL_PATH_1 ,FL_PATH_2)
FL_PATH_BP_A_2 <- append(FL_PATH_BP_A,FL_PATH_3)

DT <- rbindlist(lapply(FL_PATH_BP_A_2 ,import,header=T,sep=",",
                          setclass = "data.table"))

有没有有效而灵活的方法来解决这个案例? *每个列表都必须是list.files(),因为它们正在获取某些文件夹中的所有文件

r append
1个回答
1
投票
folders <- c("folder1","folder2","folder3")
files <- c()
for (folder in folders) {
  files <- c(list.files(folder, pattern = "*.CSV",full.name = T)))
}
© www.soinside.com 2019 - 2024. All rights reserved.