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