R - is.finite() Function
The R is.finite() function is used to check if a numeric value is finite and returns a boolean result. A complex number is regarded as finite if both the real and imaginary part are finite.
Syntax
is.finite(x)
Parameters
x |
Required. Specify column to compute on. |
Return Value
Returns TRUE if the value is finite, FALSE otherwise.
Example:
The example below shows the usage of is.finite() function.
#operating on single element atomic vector print(is.finite(0.0/0.0)) print(is.finite(10.5)) print(is.finite(1.0/0.0)) print(is.finite(Inf+2i)) cat("\nOperating on vector\n") #operating on vector v <- c(NaN, Inf, 20.8, NaN+2i) print(is.finite(v)) cat("\nOperating on matrix\n") #operating on matrix m <- matrix(c(1, Inf, 3, 4, Inf, NaN), nrow=2) print(is.finite(m)) cat("\nOperating on first column of matrix\n") #operating on first column of matrix print(is.finite(m[,1]))
The output of the above code will be:
[1] FALSE [1] TRUE [1] FALSE [1] FALSE Operating on vector [1] FALSE FALSE TRUE FALSE Operating on matrix [,1] [,2] [,3] [1,] TRUE TRUE FALSE [2,] FALSE TRUE FALSE Operating on first column of matrix [1] TRUE FALSE
❮ R Math Functions