I have a column - "issue_slip" in R dataframe - "vouchers" with values/rows such as
Issue slip: IS/001, IS/001, IS/001, IS/002, IS/002, IS/002
and another column "rec_status" with values 0 or 1. Each issue_slip row can have rec_status 0 or 1. I would like to keep only those issue_slips that have all rec_status as 0 OR 0 or 1 --> remove issue_slip rows that have all rec_status as 1.
For example,
- IS/001 - 1,
- IS/001 - 0 ,
- IS/001 - 1
should show up and not get filtered out because at least one row has rec_status = 1
I tried using the filter and subset functions but could not figure out how to go about filtering this in the same column
Sample data
base R
dplyr
data.table
Note, I'm using
rec_status %in% 0
instead ofrec_status == 0
for a reason: since we have no sample data (and often even when we do), I have no assurance that there are not anyNA
s in the data; note thatNA == 0
will returnNA
itself and therefore often fail non-defensive code, butNA %in% 0
returns false, which is often what we need (and I'm inferring it's what we want here).