Rechlay
Rechlay

Reputation: 1517

Load few csv files from the same folder

I'd like to load to R like 30-40 csv files which I have in the same folder. There is nothing more, just those files.

I want to import them as a different data.frames, let's name them: tbl1 tbl2 tbl3 tbl4

etc.

Can I load all of them at once or should I do it one bye one ?

It would be nice if script could load all of csv files in a folder, not a selected number, because in future I may have a different number of csv files.

Upvotes: 0

Views: 247

Answers (2)

Shaxi Liver
Shaxi Liver

Reputation: 1120

You should try it:

tbl = list.files(pattern="*.csv")
for (i in 1:length(tbl)) assign(tbl[i], read.csv(tbl[i]))

The name of the files you load will be exactly the same.

Upvotes: 0

Prasanna Nandakumar
Prasanna Nandakumar

Reputation: 4335

This Should Work

temp = list.files(pattern="*.csv")
myfiles = lapply(temp, read.delim)

Upvotes: 1

Related Questions