How to bring multiple cvs file in to R console box


#1

Hello all,

Lets say I am having 100 csv files in a folder and i want to read all the files one after another. and want to store them in the names like file1,file2,file3…file100.
And lets consider the actual file names are as 001.csv,002,csv…100.csv

I tried the method

filenames=paste(rep(“file”,100),1:100,sep="")
for(i in 1:100)
{
filenames[1]=read.csv(“001.csv”,header=TRUE,sep=",")
}

but it didnot work with me.

Please suggest what to do


#2

Hi Uday,

Try this -
File <- NULL
for (i in 001:100){
File[i] <- gsub(" “, “”, paste(sprintf(”%03d", (i)),".csv"), fixed = TRUE)
}
data <- NULL
for (i in 1:100) {
x <- read.csv(print(File[i], row.names = FALSE),header = TRUE, sep = “,”)
attr(x, “rownames”) <- NULL
data <- rbind(data,x)
}
Yesterday only i encountered this problem and now I see a question on AV discuss about it :smile:

Hope this helps.
Regards,
Aayush