I imagine this is pretty basic question, but I am kind of lost. I have three variables: A, B and C, that range from 0-4. I would like to take a total count of those that equal 1 and create a new variable with the total sum. For example, if variables A and B equal 1, the new variable SumABC would equal 2. I've attempted doing this with mutate, but I know there has got to be an easier way.
x <- mutate(z,
SumABC =
ifelse(A == 1, 1,
ifelse(B ==1, 1,
ifelse(C ==1, 1,
ifelse(A ==1 & B ==1, 2,
ifelse(A ==1 & C ==1, 2,
ifelse(B ==1 & C ==1, 2,
ifelse(A ==1 & B ==1 & C == 1, 3, 0))))))))