title: How to add a variable based on order of observation in a dataframe - R
body: <p>I want to add a variable value to a dataframe based on the order of the observation in the data frame. </p>
  
  <pre><code>… Subject Latency(s)
  1   A     25
  2   A     24
  3   A     25
  4   B     22
  5   B     24
  6   B     23
  </code></pre>
  
  <p>I want to add a third column called <code>Trial</code> and I want the values to be either T1, T2, or T3 based on the order of the observation and by Subject. So for example, Subject A would get T1 in row 1, T2 in row 2, and T3 in row 3. Then the same for subject B, and so on.</p>
  
  <p>Right now my approach is to use <code>group_by</code> in <code>dplyr</code> to group by Subject. But I'm not sure then how to specify the new variable using <code>mutate</code>. </p>