I'm trying to use lapply to run the same function over multiple data frames, but can't get lapply to work without assigning it to something. When I do this, I then have to go back in and re-separate the resulting lists which is annoying. Does anyone know why lapply won't just store the result over the data frames themselves? Here's a simple example:
keepCols <- c(1:6, 23, 24, 27:34, 37, 41:43)
myList <- list(x, y, z)
When I do this, all it does is print the result
lapply(myList, function(x) x[, ..keepCols])
If I assign it to something, I get a large list with what I want in it
df <- lapply(myList, function(x) x[, ..keepCols])
Why is lapply not working the way I want it to?
lapply()
. In R is call-by-value. en.wikipedia.org/wiki/Evaluation_strategy#Call_by_value – jogomyList <- lapply(...)
– Sotosl1 <- list(head(iris), tail(iris)); lapply(l1, function(i)i[3:4])
Vsl1 <- list(head(iris), tail(iris)); l1 <- lapply(l1, function(i)i[3:4])
to see what happens – Sotos