I have a dataframe and I need to give each group an ID. A group is defined as long as the value is the same.
here is the dataframe
structure(list(groups = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 1L, 1L, 4L, 4L, 4L, 4L, 1L, 1L, 3L, 3L, 3L, 3L,
2L, 2L, 2L, 2L, 2L), .Label = c("A", "B", "C", "F"), class = "factor"),
type = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L, 1L, 1L, 4L, 4L, 4L, 4L, 1L, 1L, 3L, 3L, 3L, 3L, 2L, 2L,
2L, 2L, 2L), .Label = c("Apple", "Bread", "curry", "Fish"
), class = "factor")), class = "data.frame", row.names = c(NA,
-28L))
And the result should look like this:
group ID
A 1
A 1
A 1
A 1
A 1
B 2
B 2
B 2
B 2
B 2
B 2
A 3
A 3
F 4
F 4
F 4
F 4
A 4
A 4
C 5
C 5
C 5
C 5
B 6
B 6
B 6
B 6
B 6
thx for your help!