Search code examples
rsubsetdelete-row

Easy way to delete rows that have a certain value


I have a data set with several columns and I'm working on it using R. Most of those columns have missing data, which was set as a value -200. What I want to do is to delete all the rows that have -200 in any of the columns. Is there an easy way to do this other than going by each column at a time? Can I delete all rows that a value of -200 all at once?

Thank you for your time!


Solution

  • A tidyverse option would be

    library(tidyverse)
    df %>%
       filter_all(all_vars(. != -200))
    

    data

    df <- data.frame(v1 = c(-200, 1, 2, 3), v2 = c(1, -200, 2, 4))