So below is some example data, as well as the result I hope to achieve. I've tried several different versions, of dplyr but can't seem to get it to work the way I want it to come out as:
df <- data.frame(name = c("name1", "name1", "name1", "name2", "name2", "name2", "name3", "name3", "name3"),
D1 = c(0,0,0,1,0,0,2,3,1),
D2 = c(0,1,0,3,4,0,0,0,0))
What I'm trying to get it to is where any number greater than 1 is counted per name for each name regardless of what that number is. So zero's are not counted, and any number above zero is counted as 1.
answer <- data.frame(name = c("name1", "name2", "name3"),
D1 = c(0,1,3),
D2 = c(1,2,0))
Thank you for your help.