2
I have a date.frame with two columns (CLASSWK
and IND
) and I’d like to apply a filter based on one condition, but I’m unable to do that.
I have a column CLASSWK
, that I only want to keep values that are 1 or 2. But this only applies if my other column, IND
, is different from 0.
So, basically, if IND == 0
, I just disregard my filter, but if mine IND
is any other value, so I have to apply the filter in the column CLASSWK
and remove values that are different from 1 or 2.
Man dput
:
structure(list(CLASSWK = c(1, 2, 1, 3, 5, 1, 2, 6, 7, 3), IND = c(1,
2, 3, 4, 0, 6, 0, 0, 8, 4)), class = "data.frame", row.names = c(NA,
-10L))
Code I tried to use:
library(dplyr)
x %>%
filter(case_when(IND != 0 & CLASSWK == 1 & CLASSWK == 2))
but in both cases I am removing from the basis the values where
IND == 0
and I’d like to keep them too.– Alexandre Sanches
@Alexandresanches Done, see now.
– Rui Barradas
Thank you very much!
– Alexandre Sanches