title: Observation number by group
body: <p>In R I have a data frame with observations described by several values one of which is a factor. I have sorted the dataset by this factor and would like to add a column in which I would get a number of observation on each level of the factor e.g.</p>
  
  <pre><code>factor   obsnum
  a        1
  a        2
  a        3
  b        1
  b        2
  b        3
  b        4
  c        1
  c        2
  ...
  </code></pre>
  
  <p>In SAS I do it with something like:</p>
  
  <pre><code>data logs.full;
      set logs.full;
      count + 1;
      by cookie;
      if first.cookie then count = 1;
  run;
  </code></pre>
  
  <p>How can I achieve that in R?</p>
  
  <p>Thanks,</p>