i'm trying to sum all the columns with if else condition replaced null values with 999 if not 999 it should add all columns can some one tell better one, i'm getting wrong value by using this,
like need to add sum of columns and then finally add the sum of all columns
sum((A1a(i)+A2b(i)))
sum((ifelse((df$A1a!= 999), df$A1a,0)+
ifelse((df$A2b!= 999), df$A2b,0)+
ifelse((df$A3c!= 999), df$A3c,0))
example:
A B C D
# 1 4 7 10
# 2 5 8 11
# 1 3 1 1
if B!=1 (4+5+3)
if C!=1 then add (7+8) for c and
if D! = 1for (10+11)
finally (12+15+21)=48