Note: I changed the example from when I first posted. My first example was too simplified to capture the real problem.
I have two data frames
NOTE: Check the 5th comment on the answer above. Solution should be
s1$index <- with(s1,ave(value1,state,FUN=seq_along)) s2$index <- with(s2,ave(value2,state,FUN=seq_along))
Tested and working.