I am trying to use sum
in a function, but the results are NA
, which I think may be due to integer overflow. But the class of the numbers I am using is numeric.
The function is most simply
sum((columnA-columnB)^2)
A value from columnA is 0.1376146
and from columnB is 0.272
Is is the different length of decimal places? I know how to change what is displayed, but I'm not sure that will change what R uses for sum
.
Following Joshua Ulrich's comment, before saying that you have some overflow problem, you should answer these questions:
NA
s in your data? If you sum anything with NA
s present, the result will be NA
, unless you handle it properly.That said, some solutions:
sum(..., na.rm=T)
to ignore NA
s from your object (this is the simple solution)NA
entries: sum(yourVector[!is.na(yourVector)]
(the not so simple one)sum(subset(yourDataFrame, !is.na(columnToSum))[columnToSum])
(this is like using a cannon to kill a mosquito)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With