I have a dataframe called a
It has 23 columns and around 400 rows. The last two concentration columns are C1 and C2
They contain numerical values as well as NA values (rows with both columns having NA have been removed)
I need to calculate the absolute difference between C1 and C2 (i.e. no negative nor positive net)
I normally use this code to calculate differences but I do not know how to customise it to overlook NA in one of the column and to yield absolute values
a$diff <- (a$C1 - a$C2)
Replacing NA w/another value even zero is not an option. I need to see the trend in the difference between C1 and C2 where it is applicable. Also, concentration values may themselves be zero.
I was thinking some kind of conditional statement !is.na but I do not know where to insert it or how. As in do a comparison of both C1 and C2 that neither hold NA and then do a calculation.