title: Removing NA in correlation matrix
body: <p>I am doing a correlation matrix for a dataframe of 4000 variable and I would like to remove the variables showing > 0.5 correlation, so I am using this command from the {caret} package.</p>
  
  <pre><code>removeme &lt;- findCorrelation(corrMatrix, cutoff = 0.5, verbose = FALSE)
  
  Error in if (mean(x[i, -i]) &gt; mean(x[-j, j])) { : 
  missing value where TRUE/FALSE needed
  </code></pre>
  
  <p>The data I have is highly variable, and I get NA values here and there. To start with, I couldn't find something that can deal with NA values on the help page of this command, so I decided to remove the NA values myself.</p>
  
  <p>Some variables show NA values all the way across the data, and some show few NA values. I am trying to remove the variables that are causing any NA values, so that I would be able to use the above command. Here's a minimal example of what my data looks like</p>
  
  <pre><code>dput(df) &lt;- structure(list(GK = 1:10, HGF = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 
  0L, 0L, 0L), HJI = c(2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), 
      HDF = c(5L, 6L, 8L, 9L, 5L, 2L, 4L, 3L, 2L, 1L), KLJG = c(0L, 
      0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), KLJA = c(0L, 0L, 0L, 
      0L, 0L, 0L, 0L, 0L, 0L, 0L), KDA = c(10L, 11L, 15L, 18L, 
      11L, 10L, 10L, 15L, 12L, 13L), OIE = c(NA, NA, NA, NA, NA, 
      NA, NA, NA, NA, NA), AFE = c(0L, 0L, 0L, 1L, 0L, 0L, NA, 
      NA, NA, NA)), .Names = c("GK", "HGF", "HJI", "HDF", "KLJG", 
  "KLJA", "KDA", "OIE", "AFE"), class = "data.frame", row.names = c(NA, 
  -10L))
  
  corrMatrix &lt;- cor(df,use="pairwise.complete.obs")
  </code></pre>
  
  <p>What would be the best idea to get rid of these annoying variables? I have tried Many commands but did not get to an ideal one that would get rid of these variables. Here are one of my trials:</p>
  
  <pre><code>removeme &lt;- corrMatrix[,which(as.numeric(rowSums(is.na(corrMatrix))) &gt; 100)] 
  </code></pre>
  
  <p>The issue with this command that if there was over a 100 faulty variables (giving NA in correlation matrix) the normal variables will be removed, as the columns of the normal variable will have > 100 NA values.</p>
  
  <p>I hope this edit made my question more clear. Cheers.</p>