vendredi 1 novembre 2019

How to delete entire row for x if y appears at least once in same column?

I would like to run a code in which I delete the entire row for entries of "x", if "y" appears at least once in the same column of "var1". I can't find any solution in R. Below is what I tried.

In the code below, I tried to tell R that if var1 contains at least one y, all rows containing x should be filtered out/removed.

 if (all(df$var1 %in% c("y"))) { 
 df <- filter(!var1 %in% c("x"))
 }

Unfortunately the code above doesn't return any change in df, even though y appears several times in var1.

Many thanks. I appreciate any kind of recommendation.

Aucun commentaire:

Enregistrer un commentaire