Imagine I have a data.frame
with many columns in R. I would like to select rows only where all columns have finite values.
set.seed(123) d = data.frame(matrix(sample(c(1:10, Inf, -Inf), 100, replace=T), ncol=20))
I do not want to refer to each column by name, as there are many of them. na.omit
and complete.cases
will not do the trick.
One way to do this:
d[apply(apply(d, 2, is.finite), 1, all),]
It's not beautiful. Is there a better way?
Alex source share