title: Return only columns containing NA in R
body: <p>I have the following data-frame:</p>
  
  <pre><code>i3&lt;-c(1,1,1,1,2,2)
  i2&lt;-c(NA,1,1,1,2,2)
  i1&lt;-c(1,NA,2,4,5,3)
  newdat1&lt;-data.frame(i3,i2,i1)
  print(newdat1)
    i3 i2 i1
  1  1 NA  1
  2  1  1 NA
  3  1  1  2
  4  1  1  4
  5  2  2  5
  6  2  2  3
  </code></pre>
  
  <p>I realize the solution for this is quite simple, but I am trying to return all the columns that any NA so that the final result looks like:</p>
  
  <pre><code>  i2 i1
  1 NA  1
  2  1 NA
  3  1  2
  4  1  4
  5  2  5
  6  2  3
  </code></pre>
  
  <p>I have found the following code which does the opposite:</p>
  
  <pre><code>newdat1&lt;-newdat1[, sapply(newdat1, Negate(anyNA)), drop = FALSE]
  </code></pre>
  
  <p>But I cannot find exactly what I am looking for.  Thank you.</p>