a=c(1,2,NA,4)
b=c(10,NA,30,40)
weighted.mean(a,b,na.rm = T)
The above code gives me NA
as the answer, I think na.rm
only ignores the NA values in vector a and not b. How can I ignore the NA
in vector b or weights to be specific. I just cannot change the NA to 0, I know that would do the trick but looking for a tweak in the formula itself.
weighted.mean
and make your own custom function. – Unreservedwith(na.omit(data.frame(a, b)), weighted.mean(a, b))
– Umber