Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One function to detect NaN, NA, Inf, -Inf, etc.?

Tags:

r

r-faq

nan

na

Is there a single function in R that determines if a value is NA, NaN, Inf, -Inf, or otherwise not a well-formed number?

like image 720
SFun28 Avatar asked Sep 22 '11 16:09

SFun28


People also ask

What is Isnull () sum ()?

The function dataframe. isnull(). sum(). sum() returns the number of missing values in the data set.

How do I find NaN values in Excel?

You can also test for missing values using the MATCH function. MATCH finds the position of an item in a list and will return the #N/A error when a value is not found. You can use this behavior to build a formula that returns "Missing" or "OK" by testing the result of MATCH with the ISNA function.

Which functions can be used to test a data set for missing or NA values?

nan() Function for Finding Missing values: A logical vector is returned by this function that indicates all the NaN values present. It returns a Boolean value.


1 Answers

You want is.finite

> is.finite(NA)
[1] FALSE
> is.finite(NaN)
[1] FALSE
> is.finite(Inf)
[1] FALSE
> is.finite(1L)
[1] TRUE
> is.finite(1.0)
[1] TRUE
> is.finite("A")
[1] FALSE
> is.finite(pi)
[1] TRUE
> is.finite(1+0i)
[1] TRUE
like image 125
Joshua Ulrich Avatar answered Oct 20 '22 10:10

Joshua Ulrich