title: Find names of columns which contain missing values
body: <p>I want to find all the names of columns with <code>NA</code> or missing data and store these column names in a vector. </p>
  
  <pre><code># create matrix
  a &lt;- c(1,2,3,4,5,NA,7,8,9,10,NA,12,13,14,NA,16,17,18,19,20)
  cnames &lt;- c("aa", "bb", "cc", "dd", "ee")
  mymatrix &lt;- matrix(a, nrow = 4, ncol = 5, byrow = TRUE)
  colnames(mymatrix) &lt;- cnames
  mymatrix
  #      aa bb cc dd ee
  # [1,]  1  2  3  4  5
  # [2,] NA  7  8  9 10
  # [3,] NA 12 13 14 NA
  # [4,] 16 17 18 19 20
  </code></pre>
  
  <p>The desired result: columns <code>"aa"</code> and <code>"ee"</code>.</p>
  
  <p>My attempt:</p>
  
  <pre><code>bad &lt;- character()
  for (j in 1:4){     
    tmp &lt;- which(colnames(mymatrix[j, ]) %in% c("", "NA"))
    bad &lt;- tmp
  }
  </code></pre>
  
  <p>However, I keep getting <code>integer(0)</code> as my output. Any help is appreciated.</p>