I have created a vector in which both NA and NaN are present but when I have checked the NA in vector I get true for NaN but when I checked the NaN in a vector I get false for NA I am not able to understand it

x<-c(1,2,NaN,NA,4)

is.na(x)

[1] FALSE FALSE TRUE TRUE FALSE

is.nan(x)

[1] FALSE FALSE TRUE FALSE FALSE

Firstly, you must understand what NA and NaN mean:

- NA means that the entry is not present.
- NaN means that the entry is 0/0 i.e. it can’t be computed.

Thus, NaN is included as an NA which aids when arithmetic operations are to done on the vector by removing NA values.

On the other hand, is.nan() only returns the entries that are 0/0 for which an entry that is NA does not qualify.