Creating trial number ascending list, for separate subjects in long format data frame, R?
If I understand your question correctly, and assuming that your initial data frame looks something like trial_df below, you can use the following code and the dplyr package.

library(dplyr)

# create data frame 
trial_df &lt;- tibble('subject' = c(rep('101', 3), rep('102', 3)),
                  'result' = c(32, 33, 64, 12, 18, 14))

# group by subject and add a row number
# assumes your data frame is ordered by trial number for each subject
new_df &lt;- trial_df %&gt;%
  group_by(subject) %&gt;%
  mutate(trial_number = row_number())