Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading