title: Flag first by-group in R data frame
body: <p>I have a data frame which looks like this:</p>
  
  <pre><code>id  score
  1   15
  1   18
  1   16
  2   10
  2   9
  3   8
  3   47
  3   21
  </code></pre>
  
  <p>I'd like to identify a way to flag the first occurrence of id -- similar to first. and last. in SAS.  I've tried the !duplicated function, but I need to actually append the "flag" column to my data frame since I'm running it through a loop later on.  I'd like to get something like this:</p>
  
  <pre><code>id  score   first_ind
  1   15      1
  1   18      0
  1   16      0
  2   10      1
  2   9       0
  3   8       1
  3   47      0
  3   21      0
  </code></pre>