I have a question about arithmetic behaviour in R. Regard the following piece of code
> NaN + NA
[1] NaN
>
>
> NaN + as.integer(NA)
> NA
So, I am confused that these two additions give different results. Does anybody know if this is really wanted behaviour or just some kind of bug?
Thanks in advance
In R, missing values are represented by the symbol NA (not available). Impossible values (e.g., dividing by zero) are represented by the symbol NaN (not a number).
nan() Function. is. nan() Function in R Language is used to check if the vector contains any NaN(Not a Number) value as element. It returns a boolean value for all the elements of the vector.
The NaN values are referred to as the Not A Number in R. It is also called undefined or unrepresentable but it belongs to numeric data type for the values that are not numeric, especially in case of floating-point arithmetic. To remove rows from data frame in R that contains NaN, we can use the function na. omit.
nan Function, Count, Replace & Remove. In the R programming language, NaN stands for Not a Number.
From ?NaN
:
Computations involving
NaN
will returnNaN
or perhapsNA
: which of those two is not guaranteed and may depend on the R platform (since compilers may re-order computations).
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