I have this dataframe.
library(tidyverse)
df <- tibble(
n = c(50, 40, 70),
WC = c(.012, NA, -.02),
Dic = c(.03, .06, NA),
I = c(NA, -.09, .0)
)
I want to sum the values in column n if there is a value in column WC. If there are rows with missing values in column WC, I want to skip them (i.e., value 40 in n should be excluded from sum, because there is a NA in WC row).
Then, I want to do the same with columns Dic and I - sum the values in n only if rows in columns Dic and I have no missing values, but skip the rows with NAs - and store the three sums in a vector.