-1

I have a data frame that contains a list within a each row. I would like to delete a row if it matches the criteria of the most common number with in the list being 0/ the mean of the list being 0. and then to save the new data frame.

Many Thanks

col| list.val | total
-------------------------
 1 | c(0.148573085665703, 0.149999290704727)| 5
 2 | c(0, 0)| 3
 3 | c(-0.0181932244449854, -0.026567880064249)| 2
 4 | c(-0.0181932235749854, -0.556567880064249)| 1
 5 | c(0, 0)| 5
  • 4
    Welcome to StackOverflow. Please take a look at these tips on how to produce a [minimum, complete, and verifiable example](http://stackoverflow.com/help/mcve), as well as this post on [creating a great example in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Perhaps the following tips on [asking a good question](http://stackoverflow.com/help/how-to-ask) may also be worth a read. This is a basic question in R. Have a look at `help("[")` and its examples. – lmo Sep 02 '16 at 11:34
  • 1
    Please make your example reproducible. Use the links provided at the comment above. – Sotos Sep 02 '16 at 13:11
  • What is missing to make it reproducible? – James Sep 02 '16 at 13:18

1 Answers1

0
        checker <- function(v){
            if(mean(v) == 0 | ){
                return(NA)
            }else {
                return(v)
            }
    }

df$filtered <- lapply(df$list.val, checker)
Shorpy
  • 1,549
  • 13
  • 28