I have a dataframe in R that looks like this: 
And I want to perform the following operation to each column:
((abs(a-b))+(abs(a-c))+(abs(a-d)))/200 The problem is that some rows will have NA values so when I do this:
data$E=(abs(data$a-data$b)+abs(data$a-data$c)+abs(data$a-data$d))/200) The results in the column E will be NA for many rows. Unless they don't have any NA values (like in ID1) Ideally I would like the numerator operation to stop when it encounters the first NA. Therefore for ID 4, let's say, it would look like this:
(abs(a-b)+(abs(a-c)))/200 Therefore omitting column d because of their NA values.
Any help will be appreciated. Thanks!
NAby 0? But -- is the semantics of that move coherent? If a value is not available, assuming that it is 0 is as arbitrary as assuming that it is e.g. 42. What you are trying to do seems ad hoc.a, but you are still making assumptions on missing values.