[R] Reading multiple files into R

Paul Lemmens P.Lemmens at nici.ru.nl
Fri Oct 1 09:31:02 CEST 2004


Hoi Vikas,

--On vrijdag 1 oktober 2004 10:50 +0530 Vikas Rawal <vikas at mail.jnu.ac.in> 
wrote:

> I want to read data from a number of files into R.
> Reading individual files one by one requires writing enormous amount of
> code that will look something like the following.
>
> Is there a better way of doing this?
>
These days I'm using the code below to read in each datafile I have, and 
come out with a single dataframe.

#  Concatenate the raw data files.
(datafiles <- list.files(path="../raw data/", pattern="pp.+\.dat$"))
tst <- do.call('rbind', lapply(datafiles, function(x) read.table(
  paste('../raw data/', x, sep=""), skip=1)))
rm(datafiles)




-- 
Paul Lemmens
NICI, University of Nijmegen              ASCII Ribbon Campaign /"\
Montessorilaan 3 (B.01.05)                    Against HTML Mail \ /
NL-6525 HR Nijmegen                                              X
The Netherlands                                                 / \
Phonenumber    +31-24-3612648
Fax            +31-24-3616066




More information about the R-help mailing list