Detr4
Detr4

Reputation: 79

R: How can I filter out a specific variable value from each table in my list of tables?

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!

Upvotes: 0

Views: 45

Answers (1)

jdobres
jdobres

Reputation: 11957

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)

Upvotes: 2

Related Questions