I am trying to sum lots of variables for creating a new variable. There are NA
's in some of them and I need to avoid NA
's because the outcome for every row with any NA
is another NA
:
library(tidyverse)
v1 <- c(NA, 2, 3)
v2 <- c(1, 3, 5)
datos <- tibble(v1, v2)
datos %>%
mutate(v3 = v1 + v2)
The outcome of this script is a vector NA 5 8
, what is needed as outcome is the variable 1 5 8
. I would like to know if is it mandatory replacing NA
's for zeros, which I would prefer not to.