I have a data-frame called 'batsmen'. It has close to 100k rows.
One column is called 'Inns'. It goes like this {1,1,1,1,2,2,2,1,1,1,1,1,2,2,2,2,0,0,1,1,1,1,1,2,2,2,2,2,2,2...}
I want to define a new column 'Position' in the same data-frame. It will be a conditional integer sequence (seq.int). It will start from 1, and go on till 'Inns' changes value. As soon as 'Inns' changes value, 'Position' will start from 1 again. So in the above example for 'Inns', 'Position' should look like this: {1,2,3,4,1,2,3,1,2,3,4,5,1,2,3,4,1,2,1,2,3,4,5,1,2,3,4,5,6,7....}
I can do this using for loop. But I don't want to lose on run-time because I see this as a small step in the overall program. Can you suggest an easy way without using for loop?