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 3,540 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,671
- 41
- 36
- 56
-
-
library(data.table) setwd("C:/your_files/") WD="C:/your_files/" data<-data.table(read.csv(text="Name,Address,Age,Work")) csv.list<- list.files(WD) k=1 for (i in csv.list){ temp.data<-read.csv(i) data<-data.table(rbind(data,temp.data)) if (k %% 100 == 0) print(k/length(csv.list)) k<-k+1 } – ASH Nov 14 '15 at 00:56