title: Replace with NA except last row given ID with R
body: <p>Sample data:</p>
  
  <pre><code>x &lt;- data.frame(id=c(1,1,1,2,2,7,7,7,7),dna=c(232,424,5345,45345,45,345,4543,345345,4545))
  y &lt;- data.frame(id=c(1,1,1,2,2,7,7,7),year=c(2001,2002,2003,2005,2006,2000,2001,2002))
  x &lt;- transform(x, rec = ave(id, id, FUN = seq_along))
  y &lt;- transform(y, rec = ave(id, id, FUN = seq_along))
  
  df &lt;- merge(x, y, c("id", "rec"))
  df
  </code></pre>
  
  <p>I would like to replace column values of <code>dna</code> with <code>NA</code> except the last row given <code>id</code> and <code>rec</code>. How can I do this efficiently? Ideal would be solution in base R. Thanks!</p>
  
  <p>The desired output:</p>
  
  <pre><code>   id rec   dna year
  1  1   1     NA 2001
  2  1   2     NA 2002
  3  1   3   5345 2003
  4  2   1     NA 2005
  5  2   2     45 2006
  ...
  ...
  </code></pre>