I have a function (foo
) to subset any variable from the list L
. It works perfect! But can I by default add variable weeks
to whatever
You could do:
foo <- function(List, what, time = 1){
s <- substitute(what)
s <- bquote(.(s) & weeks == time)
h <- lapply(List, function(x) do.call("subset", list(x, s)))
h1 <- Filter(NROW, h)
h2 <- lapply(List[names(h1)], function(x) subset(x, control))
Map(rbind, h1, h2)
}
# AND THEN:
lapply(1:3, function(i) foo(L, type == 1, time = i))