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
Or we can replace NA with 0 and then use the OP's code
replace
NA
data %>% mutate_each(funs(replace(., which(is.na(.)), 0))) %>% mutate(Sum= a+b+c) #or as @Frank mentioned #mutate(Sum = Reduce(`+`, .))
Based on the benchmarks using @Steven Beaupré data, it seems to be efficient as well.