1

Apologies in advance if this is already answered elsewhere, I looked but couldn't find what I needed.

I need to create an ordered id variable by group, so go from a dataset like this:

Data <- data.frame(
group = c("A", "B", "B", "B", "A"),
x = c(1, 2, 3, 4, 5),
y = c(1, 2, 2, 2, 1))

To a dataset like this:

  group x y  id
1     A 1 1   1
2     B 2 2   1
3     B 3 2   2
4     B 4 2   3
5     A 5 1   2

I know there must be an easy way, but I have not been able to figure it out.

0 Answers0