title: How to create ID column in R
body: <p>I have a longitudinal data in a long format. I want to create an ID variable based on the variable-column that identifies each observation of my data. How do I do that in R?</p>
  
  <p>Example: I have this data</p>
  
  <pre><code>name year var1 var2
   A    1    4    3
   A    2    5    1
   A    3    4    2
   B    1    .    .
   B    2    4    3
   B    3    5    1
  </code></pre>
  
  <p>I want to produce a new column called 'id' with a unique number for every name, such as:</p>
  
  <pre><code>name id year var1 var2
   A    1  1    4    3
   A    1  2    5    1
   A    1  3    4    2
   B    2  1    .    .
   B    2  2    4    3
   B    2  3    5    1
  </code></pre>
  
  <p>Any help? </p>