0

I have a list and I want to remove all the rows with "Volvo 142E" from data. any help will be appriciated.

data("mtcars")
rownames(mtcars)
data <- list(mtcars ,mtcars, mtcars, mtcars);data

out1 <- NULL
for(i in seq_along(data)) {
  out1[[i]] <- data[[i]][!(rownames(data[[i]]) %in% data[[i]] == "Volvo 142E" ), ]
}
out1

many thanks in advance

Seyma Kalay
  • 2,037
  • 10
  • 22

1 Answers1

1

You can use lapply to iterate over list and then subset the rows :

lapply(data,function(x) x[rownames(x) != "Volvo 142E", ])

Equivalent "tidy" option would be :

library(dplyr)
library(purrr)

map(data, ~.x %>% filter(rownames(.) != "Volvo 142E"))
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213