0
items = c("a", "b", "c", "d", "e", "f", "g")

a = lapply(items, function(items) list.files(pattern=paste0(items,".*\\.txt")))

a.df = do.call("rbind", lapply(a[[1]], stackfiles))
b.df = do.call("rbind", lapply(a[[2]], stackfiles))
c.df = do.call("rbind", lapply(a[[3]], stackfiles))
d.df = do.call("rbind", lapply(a[[4]], stackfiles))
e.df = do.call("rbind", lapply(a[[5]], stackfiles))
f.df = do.call("rbind", lapply(a[[6]], stackfiles))
g.df = do.call("rbind", lapply(a[[7]], stackfiles))

There's a read.table() inside my stackfiles() which will read through every file that is inside the a-g.list. How can I use the apply() to rewrite the this format, because I realized I cant avoid assigning a new variable name for each repetition, but also at the same time, I also need to increment a[[i]], that is hard part this problem.

user3697665
  • 297
  • 1
  • 6
  • 17
  • Try `lapply(item, function(i) list.files(pattern=paste0(i,".*\\.txt")))` for the first part. – Frank Oct 13 '15 at 19:05
  • 2
    What's inside `stackfiles()`? Please read the info about how to give a [minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). – Jaap Oct 13 '15 at 19:09
  • Looks like something to the effect of `do.call(rbind, lapply(seq_along(a), function(i) stackfiles(a[[i]])))` – Rich Scriven Oct 13 '15 at 20:08

0 Answers0