I have a data frame with some NA values. I need the sum of two of the columns. If a value is NA, I need to treat it as zero.
a b c d 1 2 3 4 5 NA 7 8
dplyr solution, taken from here:
dplyr
library(dplyr) dat %>% rowwise() %>% mutate(e = sum(b, c, na.rm = TRUE))