title: Find columns with all missing values
body: <p>I am writing a function, which needs a check on whether (and which!) column (variable) has all missing values (<code>NA</code>, <code>&lt;NA&gt;</code>). The following is fragment of the function:</p>
  
  <pre><code>test1 &lt;- data.frame (matrix(c(1,2,3,NA,2,3,NA,NA,2), 3,3))
  test2 &lt;- data.frame (matrix(c(1,2,3,NA,NA,NA,NA,NA,2), 3,3))
  
  na.test &lt;-  function (data) {
    if (colSums(!is.na(data) == 0)){
        stop ("The some variable in the dataset has all missing value,
       remove the column to proceed")
        }
        }
  na.test (test1)
  
  Warning message:
  In if (colSums(!is.na(data) == 0)) { :
    the condition has length &gt; 1 and only the first element will be used
  </code></pre>
  
  <p><strong>Q1:</strong> Why is the above error and any fixes ?</p>
  
  <p><strong>Q2:</strong> Is there any way to find which of columns have all <code>NA</code>, for example output the list (name of variable or column number)?</p>