Suppose you had a list of 200 tables each containing the variable "cyl". In the variable "cyl", there are three values ("4", "6", and "8"). In R, how could I filter out the value "4" from each of the 200 tables?
The code for the list generation is provided below.
output <- list()
iterations <- 200
for(i in 1:iterations){
output[[i]] <- mtcars <- mtcars[sample(nrow(mtcars), size = 15, replace = FALSE), ]
}
Any help at all is greatly appreciated!
CodePudding user response:
Turning my comment into an answer, if you have an operation you'd like to apply over a list of items, lapply
is usually the right choice:
lapply(output, subset, cyl != 4)