Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将多个文本文件导入R_R_Import - Fatal编程技术网

将多个文本文件导入R

将多个文本文件导入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 = "

我有四个文件夹,其中包含同名的文本文件(以制表符分隔),我想将所有这些文本文件导入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 = "\\"),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(即在不同的文件夹中)?您可以使用合适的正则表达式修改
列表中的模式