I have the following in an R data.table:
id | status
=============
1 | A
1 | B
2 | A
2 | B
3 | A
4 | A
5 | B
I want to show only the rows grouped by id that have an A, but not a B. So a result would be something like this:
id | status
=============
3 | A
4 | A
So far I have this:
dt[, sum(status == "A") > 0 && sum(status == "B") == 0, by = id]
which gets me:
id | status
=============
1 | FALSE
2 | FALSE
3 | TRUE
4 | TRUE
5 | FALSE
which I think is on the right track, but I don't know how to just get the rows that I want. Am I on the right track, or am I completely thinking about it the wrong way?