Skip to content
Prev 276758 / 398506 Next

lapply to list of variables

Hi:

Here's another way of doing this on the simplified version of your example:

L <- vector('list', 3)      # initialize a list of three components
## populate it
for(i in seq_along(L)) L[[i]] <- rnorm(20, 10, 3)
## name the components
names(L) <- c('Monday', 'Tuesday', 'Wednesday')
## replace values <= 10 with NA
lapply(L, function(x) replace(x, x <= 10, NA)

If you have a large number of atomic objects, you could create a
vector of the object names, make a list out of them (e.g., L <-
list(objnames)) and then mimic the lapply() as above. replace() only
works on vectors, though - Uwe's solution is more general.

HTH,
Dennis
On Tue, Nov 8, 2011 at 8:59 AM, Ana <rrasterr at gmail.com> wrote: