I have a dataframe in which I need to identify or index the start of each new trial. A new trial is indicated by variable Location from 0-8. Example below:
zPos Location
1.9148150 6
1.914815 6
1.914815 6
1.914815 6
1.914815 6
0.9018518 3
0.9018518 3
0.9009259 3
0.9009259 3
0.9009259 3
0.9009259 3
There are 72 trials in each dataframe, so each location value repeats 8 times meaning unique won't work. I am a novice when it comes to R, so I haven't tried much outside of base R and dplyr to tackle this problem.
Ideally I would like to create a new variable for trial number, example below:
zPos Location TrialNum
1.9148150 6 1
1.914815 6 1
1.914815 6 1
1.914815 6 1
1.914815 6 1
0.9018518 3 2
0.9018518 3 2
0.9009259 3 2
0.9009259 3 2
0.9009259 3 2
0.9009259 3 2
But I could also work with an index of the starting location for each new trial rather than a new variable in the dataframe.
This is my first question on stackoverflow, so I greatly appreciate any assistance or insight.