I have a directory of thousands of CSV files which, fortunately, follow a strict naming convention. I am trying to write a function that groups into separate data frames all of the files that end with the same last 7 digits.
I have a vector (u) of the 7 digit patterns to match:
v <- list.files(wd, full.names = FALSE)
u <- unique(substr(v, 9, 15))
Now I need to run each element of vector u against each file in list v, and combine all the matching files in v into a single data data frame for each value of u.
I've tried a few things with no success:
#only matches first in list
files <- list.files(pattern=u)
#makes a list of vectors with the same contents
lapply(v, function(x) list.files(pattern=u))
#nope
data <- data.frame()
for (i in 1:length(u)) {
data <- rbind(data, read.csv(v[files]))
}
A nudge or shove in the in the right direction would be greatly appreciated.
Thanks!