您如何将多个.txt文件读入R? [英] How do you read multiple .txt files into R?
本文介绍了您如何将多个.txt文件读入R?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用R可视化一些全部为.txt格式的数据.目录中有几百个文件,我想一次将它们全部加载到一张表中.
I'm using R to visualize some data all of which is in .txt format. There are a few hundred files in a directory and I want to load it all into one table, in one shot.
有帮助吗?
列出文件不是问题.但是我很难从清单到内容.我已经尝试了此处中的一些代码,但我在此部分遇到了一个错误:
Listing the files is not a problem. But I am having trouble going from list to content. I've tried some of the code from here, but I get a bug with this part:
all.the.data <- lapply( all.the.files, txt , header=TRUE)
说
Error in match.fun(FUN) : object 'txt' not found
任何能阐明此问题的代码片段将不胜感激.
Any snippets of code that would clarify this problem would be greatly appreciated.
推荐答案
感谢所有答案!
同时,我也自己破解了一个方法.让我知道它是否有用:
In the meanwhile, I also hacked a method on my own. Let me know if it is any useful:
library(foreign)
setwd("/path/to/directory")
files <-list.files()
data <- 0
for (f in files) {
tempData = scan( f, what="character")
data <- c(data,tempData)
}
这篇关于您如何将多个.txt文件读入R?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文