[英]r Reading multiple .text files and Error : more columns than column names
我正在尝试根据以下脚本读取将近30000个管道(|)分隔的文本文件
mypath = "path/to/my/text/files/directory"
setwd(mypath)
# Create list of text files
txt_files_ls = list.files(path=mypath, pattern="*.txt")
# Read the files in, assuming comma separator
txt_files_df <- lapply(txt_files_ls, function(x) {read.table(file = x, header = T, sep ="|")})
# Combine them
Combined_df <- do.call("rbind", lapply(txt_files_df, as.data.frame))
我收到一个错误
Error in read.table(file = x, header = T, sep = "|") :
more columns than column names
In addition: There were 37 warnings (use warnings() to see them)
我的文件夹中有30000个文本文件,实际上无法打开每个文件并检查哪个文件的列数超出了预期。
如果有人可以帮助我解决此错误,将很有帮助。 提前致谢。
最有可能的是,数据中的某些文本字段带有|
其中,哪个read.table()
令人困惑
尝试使用功能更强大的data.table::fread()
代替read.table()
library(data.table)
fread("filename.csv")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.