I am trying to generate a sequence variable for each subject in group with R. I have the variable (id_group) of the group and I would like to create a sequence variable at subject level (id_sub). In STATA is easy but I cannot find the way to obtain the same with R.
| id_group | id_sub |
|---|---|
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 1 | 4 |
| 2 | 1 |
| 2 | 2 |
| 3 | 1 |
| 4 | 1 |
| 4 | 2 |
Thanks