I have a file called "data" which consists of 330 cvs files.If i import, i can't import entire folder.It shows me to select one by one.Help me how to import that entire folder in r studio.
Asked
Active
Viewed 2,675 times
-2
-
2This might help: http://stackoverflow.com/questions/11433432/importing-multiple-csv-files-into-r . I assume by "entire folder" you mean all csv files that exist there. – AntoniosK Nov 11 '15 at 14:27
-
It would help if you posted the code you are using. – Heroka Nov 11 '15 at 14:33
1 Answers
0
something like that should do it
setwd("where is your folder")
#
#List file subdirectories
folders<- list.files(path = "yourfolder")
#
#Get all files...
files <- rep(NA,0)
for(i in c(1:length(folders)))
{
files.i <- list.files(path = noquote(paste("yourfolder/",folders[i], "/", sep = "")))
n <- length(files.i)
files.i <- paste(folders[i], files.i, sep = "/")
files <- c(files, files.i)
}
#
#
#Read first data file (& add file name as separate column)
T1 <- read.delim(paste("yourfolder/", files[1], sep = ""), sep = "", header=TRUE)
T1 <- cbind(T1, "FileName" = files[1])
MLavoie
- 9,277
- 40
- 37
- 54