我有四个文件夹,其中包含同名的文本文件(制表符分隔),我想将所有这些文本文件导入 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"))
这个例子工作得很好,虽然我希望使用循环或其他函数来生成这个变量,而不必单独导入所有文件。有没有人有什么建议?