title: Dropping/removing last/first row in each group R
body: <p>Here is my dataframe:</p>
  
  <pre><code>categ &lt;- c('a','a','a','b','b')
  value &lt;- c(1,2,5,4,5)
  df &lt;- data.frame(categ, value)
  </code></pre>
  
  <p>I would like to group by <code>categ</code> column and drop the first/last element in each group. Ideally I would like to create a column with indication of the first/last element in each group. Here is what I tried, but it did not work:</p>
  
  <pre><code>library('plyr')
  ddply(df, .(categ), function(x) x[-nrow(x)])
  </code></pre>
  
  <p>P.S. This is probably duplicate question, but I am new to R and R is very cryptic, so I cannot port solutions immediately.</p>