Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Language NaN + NA behaviour

Tags:

r

nan

na

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

like image 984
Sven Hager Avatar asked Jul 04 '12 12:07

Sven Hager


People also ask

What is the difference between NA and NaN in R?

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).

Is NaN () in R?

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.

How do I get rid of NaN in R?

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.

What does NaN stand for in R?

nan Function, Count, Replace & Remove. In the R programming language, NaN stands for Not a Number.


1 Answers

From ?NaN:

Computations involving NaN will return NaN or perhaps NA: which of those two is not guaranteed and may depend on the R platform (since compilers may re-order computations).

like image 53
shhhhimhuntingrabbits Avatar answered Oct 19 '22 12:10

shhhhimhuntingrabbits