[R] Reading multiple .csv-files and assigning them to variable names

Sarah Moens sarah_m at telenet.be
Fri Oct 29 11:16:36 CEST 2010


Hi all,

I've been trying to find a solution for the problem of reading
multiple files and storing them in a variable that contains the names
by which I want to call the datasets later on.

For example (5 filenames):

- The filenames are stored in one variable:
filenames = paste(paste('name', '_', 1:5, sep = ''), '.csv', sep = '')

- Subsequently I have a variable just containing the meaningful names
for the dataset
meaningfulnames = c('name1','name2'...,'name5')

- I want to link each of these names to the data that is read

for (i in 1:5)
{
     meaningfulnames[i] = read.csv(filenames[i], header = TRUE, sep = ',')
}


I need to read in quite a lot of datafiles. I have a code doing this
one at a time, but since the number of datafiles I need to read will
increase in the future, I want to make sure I have a more flexible
solution for this.

Thanks a lot for your help. I have tried to look in the help pages and
also came across dbfread, but I can't seem to find something I can use
or understand at this point.


Sarah



More information about the R-help mailing list