[R] Any existing functions for reading and extracting data from path names?

Ista Zahn izahn at psych.rochester.edu
Fri Mar 11 17:52:33 CET 2011


Hi helpeRs,

I have inherited a set of data files that use the file system as a
sort of poor man's database, i.e., the data files are nested in
directories that indicate which city they come from. For example:

dir.create("deleteme")
for(i in paste("deleteme", c("New York", "Los Angeles"), sep="/")) {
    dir.create(i)
    for(j in paste("data", 1:2, ".csv", sep="")) {
        write.csv(data.frame(x=1:10), file=paste(i, j, sep="/"))
    }
}

list.files("deleteme", recursive=TRUE)

What I want to end up with is

  x        city wave
  1    New York    1
  1 Los Angeles    1
  1    New York    2
  1 Los Angeles    2

I've started writting a simple function to do this, but it seems like
a common situation and I'm wondering if there are any packages or
functions that might make this easier.

Thanks!
Ista
-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list