× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

finding rows which don't have NA in a particular column if it already didn't have any NA

Utkarsh Upadhyay
Apr 16, 2015
<p>The problem is not limited to NAs. It happens if the indexing vector is empty. The <em>hope</em> is that the whole vector will be returned, but actually, <code>x[numeric(0)]</code> (<code>x</code> indexed by a vector of length <code>0</code>) returns an empty vector.</p> <p>For example, consider the following:</p> <pre><code>&gt; df[ c(-1), ] # Negative indexing col1 col2 2 1 2 3 1 2 4 1 2 5 NA 2 &gt; df[ c(), ] # numeric(0) [1] col1 col2 &lt;0 rows&gt; (or 0-length row.names) &gt; df[ c(1), ] # Positive indexing col1 col2 1 1 2 </code></pre> <p>See section 8.1.13 in the <a href="http://www.burns-stat.com/pages/Tutor/R_inferno.pdf" rel="nofollow">R inferno</a> for a more general explanation and work arounds.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/28922909/finding%20rows%20which%20don't%20have%20NA%20in%20a%20particular%20column%20if%20it%20already%20didn't%20have%20any%20NA/28923026">Stack Overflow</a>.</p>

Get New Tutorials Delivered to Your Inbox

New tutorials will be sent to your Inbox once a week.

comments powered by Disqus