I\'d like to check if a data.frame has any non-finite elements.
This seems to evaluate each column, returning FALSE for each (I\'m guessing its evaluating the data.f
I'm assuming the error you are getting is the following:
> any( is.infinite( z ) )
Error in is.infinite(z) : default method not implemented for type 'list'
This error is because the is.infinite()
and the is.finite()
functions are not implemented with a method for data.frames. The is.na()
function does have a data.frame method.
The way to work around this is to apply()
the function to every row, column, or element in the data.frame. Here's an example using sapply()
to apply the is.infinite()
function to each element:
x <- c(1:10, NA)
y <- c(1:11)
z <- data.frame(x,y)
any( sapply(z, is.infinite) )
## or
any( ! sapply(z, is.finite) )