0

I have a data frame in R. In one of the columns, I'm storing lists. I need to remove a number from all of the lists in this column that contain it.

example <- data.frame(matrix(NA_real_, nrow=10, ncol=1))
colnames(example) <- "col"
x <- list(c(1,2,3,4))
for(y in 1:10) {
  example$col[y] <- x
}

This generates a data frame containing 10 lists of length 4 (containing the values 1,2,3,4). I want to remove each element from every sublist with a specific value (1 in this case). How can I do this in the most efficient way?

r829
  • 161
  • 1
  • 10
  • 3
    @r829 The example you posted does not work for me. It throws a bunch of warnings about the number of items being replaced. When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. This makes it easier to help you. – MrFlick Aug 08 '18 at 21:12
  • `lapply(lst_of_df, \`[<-\`, , "col", newval)` (note the empty comma). – r2evans Aug 08 '18 at 21:19

0 Answers0