How to check a data.frame for any non-finite

前端 未结 4 977
渐次进展
渐次进展 2021-01-01 20:57

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

4条回答
  •  青春惊慌失措
    2021-01-01 21:37

    If you type methods(is.na) you'll see that it has a data.frame method, which probably explains why it works the way you expect, where is.finite does not. The usual solution would be to write one yourself, since it's only one line. Something like this maybe,

    is.finite.data.frame <- function(obj){
        sapply(obj,FUN = function(x) all(is.finite(x)))
    }
    

提交回复
热议问题