I have a dataset which is kinda like this:
df <- tibble(group = c(1,1,1,2,2,3,3),
type = c("HOME", "MAIL", "HOME", "HOME", "HOME",
"MAIL", "MAIL"),
count = c(3,4,4,3,3,2,2))
In my dplyr pipe, I would like to do a conditional filter, such that for each group if there is any type == "HOME", it will filter out from that group any TYPE == "MAIL", if there is no "HOME", then keep the "MAIL". As eventually I summarize the count, and would like the output of that to be
group 1 = 7, group 2 = 6, group 3 = 4.
Any help would be appreciated