Let’s say that there are three columns in mydata. There are multiple rows for each ID and their corresponding “case” value (character). I need to count number of a’s for each ID, and if >= 3, then delete the whole ID rows, if not, keep it.
What I have:
mydata <- data.frame(id=c(1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,4), case=c("a","b","c","a","a","a","a","c","c","a","a","a","c","a","b","c","a","b"), value=c(1,1,1,1,1,1,1,2,2,2,2,1,1,1,1,2,2,2))
what I need:
id case value
6 2 a 1
7 2 a 1
8 2 c 2
9 2 c 2
14 4 a 1
15 4 b 1
16 4 c 2
17 4 a 2
18 4 b 2