is there an elegant way to handle NA as 0 (na.rm = TRUE) in dplyr?
data <- data.frame(a=c(1,2,3,4), b=c(4,NA,5,6), c=c(7,8,9,NA))
data %>% mutate(sum = a + b + c)
a b c sum
1 4 7 12
2 NA 8 NA
3 5 9 17
4 6 NA NA
but I like to get
a b c sum
1 4 7 12
2 NA 8 10
3 5 9 17
4 6 NA 10
even if I know that this is not the desired result in many other cases
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…