I have a list of dataframes "ldf" and want to keep specific columns in each df of this list (those columns have the same name in each df)
I tried it like this which obviously failed,..
newList <-
lapply(names(ldf), function(i){
x <- ldf[[ i ]]
x <- x[c("Var1", "Var2")]
})
Example:
ldf <- list(data.frame(a = 1:5, b = 1:5, c = 1:5), data.frame(a = 1:5, b = 1:5, c = 1:5))
When only keeping Var1 and Var2 the new list should be:
list(data.frame(a = 1:5, b = 1:5), data.frame(a = 1:5, b = 1:5))