Generating Time in a Data Frame

There are two code variations I use to generate time indexes. If I need time cycles

  id    score time
1  a 16.37477    1
2  b 23.50091    2
3  c 17.49848    3
4  a 11.83472    1
5  b 23.48400    2
6  c 23.82594    3
7  a 19.00089    1
8  b 14.25190    2
9  c 27.68808    3

then I use a sequence command.

time <- seq(from = 1, to = 3, each = 3)

If I need time ordered

  id    score time
1  a 19.93433    1
2  a 20.82730    1
3  a 29.10959    1
4  b 25.48347    2
5  b 22.87176    2
6  b 19.10510    2
7  c 18.65874    3
8  c 19.68696    3
9  c 26.87015    3

then I use a replicate command.

time <- rep(c(1:3), each = 3)

Bo\(^2\)m =)