title: Using is.na in R to get Column Names that Contain NA Values
body: <p>Given the example data set below: </p>
  
  <pre><code>df &lt;- as.data.frame(matrix( c(1, 2, 3, NA, 5, NA, 
                                7, NA, 9, 10, NA, NA), nrow=2, ncol=6))
  
  names(df) &lt;- c(  "varA", "varB", "varC", "varD", "varE", "varF")
  
  print(df)
  
    varA varB varC varD varE varF
  1    1    3    5    7    9   NA
  2    2   NA   NA   NA   10   NA
  </code></pre>
  
  <p>I'd like to be able to use kmeans(...) on data sets without having to manually check or delete variables that contain NA <strong>anywhere</strong> within the variable. While I'm asking right now for kmeans(...) I'll be using a similar process for other things, so a kmeans(...) specific answer won't totally answer my question. </p>
  
  <p>The manual version of what I'd like is: </p>
  
  <pre><code>kmeans_model &lt;- kmeans(df[, -c(2:4, 6)], 10) 
  </code></pre>
  
  <p>And the pseudo-code would be: </p>
  
  <pre><code>kmeans_model &lt;- kmeans(df[, -c(colnames(is.na(df)))], 10) 
  </code></pre>
  
  <p>Also, I don't want to delete the data from df.  Thanks in advance.</p>
  
  <p>(Obviously kmeans(...) wouldn't work on this example data set but I can't recreate the real data set)</p>