title: How to delete rows from a dataframe that contain n*NA
body: <p>I have a number of large datasets with ~10 columns, and ~200000 rows. Not all columns contain values for each row, although at least one column must contain a value for the row to be present, I would like to set a threshold for how many <code>NA</code>s are allowed in a row.</p>
  
  <p>My Dataframe looks something like this: </p>
  
  <pre><code> ID q  r  s  t  u  v  w  x  y  z
   A  1  5  NA 3  8  9  NA 8  6  4
   B  5  NA 4  6  1  9  7  4  9  3 
   C  NA 9  4  NA 4  8  4  NA 5  NA
   D  2  2  6  8  4  NA 3  7  1  32 
  </code></pre>
  
  <p>And I would like to be able to delete the rows that contain more than 2 cells containing NA to get</p>
  
  <pre><code>ID q  r  s  t  u  v  w  x  y  z
   A 1  5  NA 3  8  9  NA 8  6  4
   B 5  NA 4  6  1  9  7  4  9  3 
   D 2  2  6  8  4  NA 3  7  1  32 
  </code></pre>
  
  <p><code>complete.cases</code> removes all rows containing any <code>NA</code>, and I know one can delete rows that contain <code>NA</code> in certain columns but is there a way to modify it so that it is non-specific about which columns contain <code>NA</code>, but how many of the total do?</p>
  
  <p>Alternatively, this dataframe is generated by merging several dataframes using</p>
  
  <pre><code>    file1&lt;-read.delim("~/file1.txt")
      file2&lt;-read.delim(file=args[1])
  
      file1&lt;-merge(file1,file2,by="chr.pos",all=TRUE)
  </code></pre>
  
  <p>Perhaps the merge function could be altered? </p>
  
  <p>Thanks</p>