title: How to check each element of a data frame for NA and print their position individually (not as a vector)
body: <p>I'm trying to give an automated report of NAs in a data frame:</p>
  <pre><code>#####create data frame
  
  expl_data1 &lt;- data.frame(var1 = c(NA, 7, 8, 9, 3), 
                           var2 = c(4, 1, NA, NA, 4), 
                           var3 = c(1, 4, 2, 9, 6), 
                           var4 = c(&quot;Hello&quot;, &quot;I am not NA&quot;, NA, &quot;I love R&quot;, NA)) 
  
  
  #####check each element for NA
  out&lt;-apply(is.na(expl_data1), 2, which) 
  
  
  ####print a message with the NA's position
  
  for (i in 1:length(out)){
    if (out[i] != &quot;integer(0)&quot;){
  print(paste(&quot;Please remove missing values from &quot;,names(out[i]), &quot;, line &quot;, out[i], sep= &quot;&quot;))
    }
  }
  </code></pre>
  <p>What is printed:</p>
  <pre><code>&gt; [1] &quot;Please remove missing values from var1, line 1&quot; 
  
  &gt; [1] &quot;Please remove missing values from var2, line 3:4&quot; 
  
  &gt; [1] &quot;Please remove missing values from var4, line c(3, 5)&quot;
  </code></pre>
  <p>The output is fine if there is only one NA in the column. ButI'm not happy with the output for multiple NAs. How can I access and print the positions individually? What I want is</p>
  <pre><code>&gt; [1] &quot;Please remove missing values from var1, line 1&quot;
   
  &gt; [1] &quot;Please remove missing values from var2, line 3&quot; 
  
  &gt; [1] &quot;Please remove missing values from var2, line 4&quot; 
  
  &gt; [1] &quot;Please remove missing values from var4, line 3&quot;
  
  &gt; [1] &quot;Please remove missing values from var4, line 5&quot;
  </code></pre>