There are probably better ways but one could use tapply on the IDs and toss in a function that returns a sequence.
# Example data
dat <- data.frame(ID = rep(1:3, c(2, 3, 5)), val = rnorm(10))
# Using tapply with a function that returns a sequence
dat$number.in.group <- unlist(tapply(dat$ID, dat$ID, function(x){seq(length(x))}))
dat
which results in
> dat
ID val number.in.group
1 1 -0.454652118 1
2 1 -2.391824247 2
3 2 0.530832021 1
4 2 -1.671043812 2
5 2 -0.045261549 3
6 3 2.311162484 1
7 3 -0.525635803 2
8 3 0.008588811 3
9 3 0.078942033 4
10 3 0.324156111 5