importing several text files into R
import, r
Solution
How about this?
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")
Problem
I have four folders which contain text files (tab delimited) of the same names, I would like to import all of these text files into a data.frame. For example: ``` 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")) ``` This example works fine, although I was hoping of using a loop or some other function to generate this variable without having to import all of the files individually. Does anyone have any suggestions?