将多个文本文件导入R
我有四个文件夹,其中包含同名的文本文件(以制表符分隔),我想将所有这些文本文件导入data.frame。例如:将多个文本文件导入R,r,import,R,Import,我有四个文件夹,其中包含同名的文本文件(以制表符分隔),我想将所有这些文本文件导入data.frame。例如: TopFolder = "G:\\University" SubFolder = list.files(TopFolder) #find the name of the folders in the current directory DateTime = rbind(read.table(paste(TopFolder,SubFolder[1],"Data.txt",sep = "
TopFolder = "G:\\University"
SubFolder = list.files(TopFolder)
#find the name of the folders in the current directory
DateTime = rbind(read.table(paste(TopFolder,SubFolder[1],"Data.txt",sep = "\\"),sep="\t"),
read.table(paste(TopFolder,SubFolder[2],"Data.txt",sep = "\\"),sep="\t"),
read.table(paste(TopFolder,SubFolder[3],"Data.txt",sep = "\\"),sep="\t"),
read.table(paste(TopFolder,SubFolder[4],"Data.txt",sep = "\\"),sep="\t"))
这个例子工作得很好,尽管我希望使用循环或其他函数来生成这个变量,而不必单独导入所有文件。有人有什么建议吗 这个怎么样
lf = list.files(path = "G:\\University", pattern = "Data.txt",
full.names = TRUE, recursive = TRUE, include.dirs = TRUE)
library(plyr)
DateTime = ldply(lf, read.table, sep = "\t")
这个怎么样
lf = list.files(path = "G:\\University", pattern = "Data.txt",
full.names = TRUE, recursive = TRUE, include.dirs = TRUE)
library(plyr)
DateTime = ldply(lf, read.table, sep = "\t")
这很有效。如何将其更改为导入多个文本文件。假设我想先导入Data.txt,然后导入与Data.txt存储方式相同的Data2.txt(即在不同的文件夹中)?您可以使用合适的正则表达式修改
列表中的模式。如何将其更改为导入多个文本文件。假设我想先导入Data.txt,然后导入以与Data.txt相同的方式存储的Data2.txt(即在不同的文件夹中)?您可以使用合适的正则表达式修改列表中的模式