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

Returning all rows that don't contain a certain value

Example data frame:

> df <- data.frame(A = c('a', 'b', 'c'), B = c('c','d','e'))
> df
  A B
1 a c
2 b d
3 c e

The following returns all rows in which any value is "c"

> df %>% filter_all(any_vars(. == "c"))
  A B
1 a c
2 c e

How do I return the inverse of this, all rows in which no value is ever "c"? In this example, that would be row 2 only. Tidyverse solutions preferred, thanks.

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

EDIT: To be clear, I am asking about exact matching, I don’t care if a value contains a "c", just if the value is exactly "c".

>Solution :

dplyr

FYI, filter_all has been superseded by the use of if_any or if_all.

df %>%
  filter(if_all(everything(), ~ . != "c"))
#   A B
# 1 b d
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