title: How to delete a row from a data.frame without losing the attributes
body: <p>for starters: I searched for hours on this problem by now - so if the answer should be trivial, please forgive me...</p>
  
  <p>What I want to do is delete a row (no. 101) from a data.frame. It contains test data and should not appear in my analyses. My problem is: Whenever I subset from the data.frame, the attributes (esp. comments) are lost.</p>
  
  <pre><code>str(x)
  # x has comments for each variable
  x &lt;- x[1:100,]
  str(x)
  # now x has lost all comments
  </code></pre>
  
  <p>It is well documented that subsetting will drop all attributes - so far, it's perfectly clear. The manual (e.g. <a href="http://stat.ethz.ch/R-manual/R-devel/library/base/html/Extract.data.frame.html">http://stat.ethz.ch/R-manual/R-devel/library/base/html/Extract.data.frame.html</a>) even suggests a way to preserve the attributes:</p>
  
  <pre><code>## keeping special attributes: use a class with a
  ## "as.data.frame" and "[" method:
  
  
  as.data.frame.avector &lt;- as.data.frame.vector
  
  `[.avector` &lt;- function(x,i,...) {
    r &lt;- NextMethod("[")
    mostattributes(r) &lt;- attributes(x)
    r
  }
  
  d &lt;- data.frame(i= 0:7, f= gl(2,4),
                  u= structure(11:18, unit = "kg", class="avector"))
  str(d[2:4, -1]) # 'u' keeps its "unit"
  </code></pre>
  
  <p>I am not yet so far into R to understand what exactly happens here. However, simply running these lines (except the last three) does not change the behavior of my subsetting. Using the command subset() with an appropriate vector (100-times TRUE + 1 FALSE) gives me the same result. And simply storing the attributes to a variable and restoring it after the subset, does not work, either.</p>
  
  <pre><code># Does not work...
  tmp &lt;- attributes(x)
  x &lt;- x[1:100,]
  attributes(x) &lt;- tmp
  </code></pre>
  
  <p>Of course, I could write all comments to a vector (var=>comment), subset and write them back using a loop - but that does not seem a well-founded solution. And I am quite sure I will encounter datasets with other relevant attributes in future analyses.</p>
  
  <p>So this is where my efforts in stackoverflow, Google, and brain power got stuck. I would very much appreciate if anyone could help me out with a hint. Thanks!</p>