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.frame as a list):
any( !is.finite( x ) )
I don’t understand why this behaves differently from the above, but it works fine if just checking for NAs:
any( !is.na( x ) )
I’d like the solution to be as efficient as possible. I realize I can just do…
any( !is.finite( as.matrix( x ) ) )
If you type
methods(is.na)you’ll see that it has adata.framemethod, which probably explains why it works the way you expect, whereis.finitedoes not. The usual solution would be to write one yourself, since it’s only one line. Something like this maybe,