I want to label number in the same group.I want to group by date
then give number in the same group.
Here is my data sample:
df <- data.frame(id = c("RM125","RM126","RM121","RM120","RM128","RM129","RM131","RM133","RM135","RM132"),
date = c(rep("1110101",6),rep("1110102",4)))
Deisre Output like:
ID Date label
RM125 1110101 1
RM126 1110101 1
RM121 1110101 1
RM120 1110101 1
RM128 1110101 1
RM129 1110101 1
RM131 1110102 2
RM133 1110102 2
RM135 1110102 2
RM132 1110102 2
I have tried many code like
df %>% group_by(date) %>% mutate(row_number())
df %>% group_by(date) %>% mutate(group = match(date, unique(date)))
Still can't work.Any tip is appreciated.