I compared your anwsers and IShouldBuyABoat is the most promissing. I found that function ave could be applied even if dataset is not sorted according to the grouping variable.
Let consider dataset:
dane<-data.frame(g1=c(-1,-2,-2,-2,-3,-3,-3,-3,-3),
g2=c('reg','pl','reg','woj','woj','reg','woj','woj','woj'))
Joran anwser and applied to my example:
> sequence(rle(as.character(dane$g2))$lengths)
[1] 1 1 1 1 2 1 1 2 3
Simon Urbanek proposition and results:
> unlist(lapply(table(dane$g2),seq.int))
pl reg1 reg2 reg3 woj1 woj2 woj3 woj4 woj5
1 1 2 3 1 2 3 4 5
IShouldBuyABoat code gives correct anwser:
> as.numeric(ave(as.character(dane$g1),as.character(dane$g1),FUN=seq_along))
[1] 1 1 2 3 1 2 3 4 5