【发布时间】:2021-09-01 17:44:52
【问题描述】:
我正在使用 R。我有一系列 txt 文件,所有这些文件都是 ; 分隔的。我想将这些文件组合成 1 个数据框。每个单独的文件在第一行都有变量名。
我在网上找到了一篇有用的帖子。 How to import multiple .csv files at once?。我正在使用 rbindlist 来执行此操作,但如果有更简单的方法可以导入此数据,我愿意接受建议。
这是我的代码。
# create list of files
temp <- NULL
temp <- as.list (list.files ("F:/Desktop/data"))
temp
# now rbind the list using rbindlist
data <- NULL
data <- rbindlist(temp, fill=FALSE, idcol=NULL)
is.list (temp)
typeof (temp)
当我运行这段代码时,我得到一个错误
Error in rbindlist(temp, fill = FALSE, idcol = NULL) :
Item 1 of input is not a data.frame, data.table or list
但是,当我使用 is.list 和 typeof 检查 temp 时,它显示为一个列表。我不确定为什么 rbindlist 没有将列表作为列表读取。 rbindlist 是导入此数据的最佳方式吗?
【问题讨论】:
标签: r data.table