Dear all, I am trying to read a bunch of csv files using read.table() that are named "test_xxxxxx.csv" where "xxxxxx" has no particular pattern. Is there a way of reading all the files by specifying a truncated file name e.g. "test_" with some wild card characters, or would I have to laboriously create some vector with the "xxxxxx" names and iterate or lapply() over it? Kind regards Chibisi [[alternative HTML version deleted]]
Try this: sapply(dir(patt="^test_"), read.table, sep = ";", header = TRUE) On Tue, Nov 11, 2008 at 3:06 PM, <chibco@gmail.com> wrote:> Dear all, > > I am trying to read a bunch of csv files using read.table() that are named > "test_xxxxxx.csv" where "xxxxxx" has no particular pattern. Is there a way > of reading all the files by specifying a truncated file name e.g. "test_" > with some wild card characters, or would I have to laboriously create some > vector with the "xxxxxx" names and iterate or lapply() over it? > > Kind regards > > Chibisi > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
?dir Hadley On Tue, Nov 11, 2008 at 11:06 AM, <chibco at gmail.com> wrote:> Dear all, > > I am trying to read a bunch of csv files using read.table() that are named > "test_xxxxxx.csv" where "xxxxxx" has no particular pattern. Is there a way > of reading all the files by specifying a truncated file name e.g. "test_" > with some wild card characters, or would I have to laboriously create some > vector with the "xxxxxx" names and iterate or lapply() over it? > > Kind regards > > Chibisi > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- http://had.co.nz/
<chibco <at> gmail.com> writes:> I am trying to read a bunch of csv files using read.table() that are named > "test_xxxxxx.csv" where "xxxxxx" has no particular pattern. Is there a way > of reading all the files by specifying a truncated file name e.g. "test_" > with some wild card characters, or would I have to laboriously create some > vector with the "xxxxxx" names and iterate or lapply() over it?Well, it's probably not that laborious; the example use a slightly different pattern from your's for testing. It's anyway a good idea to factor out the processing of the file, so you end up with: datafiles = dir(patter="nwu(.*).dat") for(datafile in datafiles) processFile(datafile) Dieter