I have a tibble which resembles the following:
data<-tibble(ref=c("ABC", "ABC", "XYZ", "XYZ", "FGH", "FGH", "FGH"),
type=c("A", "B", "A", "A", "A", "A", "B"))
ref type
1 ABC A
2 ABC B
3 XYZ A
4 XYZ A
5 FGH A
6 FGH A
7 FGH B
I need to group by ref and if--within a group--type B is present, return that row, else default to return any row (but only 1 row) of type A.
Expected output:
ref type
1 ABC B
2 XYZ A
3 FGH B