R is there a way to find Inf/-Inf values?
In analogy to is.na
, you can use is.infinite
to find occurrences of infinites.
You're probably looking for is.finite
, though I'm not 100% certain that the problem is Infs in your input data.
Be sure to read the help for is.finite
carefully about which combinations of missing, infinite, etc. it picks out. Specifically, this:
> is.finite(c(1,NA,-Inf,NaN))
[1] TRUE FALSE FALSE FALSE
> is.infinite(c(1,NA,-Inf,NaN))
[1] FALSE FALSE TRUE FALSE
One of these things is not like the others. Not surprisingly, there's an is.nan
function as well.
Take a look at with
, e.g.:
> with(df, df == Inf)
foo bar baz abc ...
[1,] FALSE FALSE TRUE FALSE ...
[2,] FALSE TRUE FALSE FALSE ...
...
randomForest's 'NA/NaN/Inf in foreign function call' is often a false warning, and really irritating:
- you will get this if any of the variables passed is character
- actual NaNs and Infs almost never happen in clean data
My fast-and-dirty trick to narrow things down, do a binary-search on your variable list, and use token parameters like ntree=2
to get an instant pass/fail on the subset of variables:
RF <- randomForest(prePrior1[m:n],ntree=2,...)