Tests if a vector contains any non-finite values
(Inf, -Inf, NaN, or NA).
Value
For is.nonfinite() and is.nf(), a logical vector of the same
length as x.
For anyNF(), an integer or real vector of length one with value
the 1-based index of the first non-finite value if any,
otherwise 0.
Details
is.nonfinite() (and alias is.nf()) check for non-finite
values, returning a logical vector of the same length as x,
whereas anyNF() returns an index immediately when encountering
a non-finite value.
is.nonfinite() and anyNF() are S3 generics, so custom
methods can be defined for different object types.
Similar to is.finite(), is.nonfinite() returns all
TRUE for character and raw vectors, and anyNF() returns 1L.
Examples
is.nonfinite(1:10)
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
anyNF(1:10)
#> [1] 0
is.nonfinite(c(1, 2, NA, 4))
#> [1] FALSE FALSE TRUE FALSE
anyNF(c(1, 2, NA, 4))
#> [1] 3
is.nonfinite(c(1, 2, NaN, 4))
#> [1] FALSE FALSE TRUE FALSE
anyNF(c(1, 2, NaN, 4))
#> [1] 3
is.nonfinite(c(1, 2, Inf, 4))
#> [1] FALSE FALSE TRUE FALSE
anyNF(c(1, 2, Inf, 4))
#> [1] 3
is.nf(c(1, 2, -Inf, 4))
#> [1] FALSE FALSE TRUE FALSE
anyNF(c(1, 2, -Inf, 4))
#> [1] 3
