Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R, TRUE/FALSE needed in FindCorrelation

Tags:

r

r-caret

I've created a simple correlation matrix in R and I'm trying to use caret for feature selection so I can remove the highly correlated X attributes.

Here is my code:

highlyCorrelated <- findCorrelation(correlationMatrix, cutoff = 0.90, verbose = FALSE, names = TRUE, exact = ncol(correlationMatrix) < 100)
  • highlyCorrelated is the name for the new object
  • correlationMatrix is the name of my correlation matrix

I'm getting the following error regardless of how I enter the function into R. Even if I only use one parameter I still get this error:

Error in if (x[i, j] > cutoff) { : missing value where TRUE/FALSE needed

Any thoughts?

like image 221
DataGuy Avatar asked Jun 06 '26 17:06

DataGuy


1 Answers

I had the same problem and @user20650 answer was correct. I always do the same "preprocess" to ensure finCorrelation works:

nums <- sapply(data, is.numeric)
data.numeric <- data[ , nums]

data.without_na <- na.omit(data.numeric)
cor_matrix <- cor(data.without_na)

findCorrelation(cor_matrix, 0.7)
like image 156
mjimcua Avatar answered Jun 09 '26 06:06

mjimcua