I have a data.table or a data.frame
library(data.table)
DT <- data.table(id = 1:9, name= rep(c('b','a','c'), each = 3))
where the column name
is manually ordered, but always grouped. How can I calculate the name_order
column to achieve the result below in either Data.table or dplyr?
id name name_order
1: 1 b 1
2: 2 b 1
3: 3 b 1
4: 4 a 2
5: 5 a 2
6: 6 a 2
7: 7 c 3
8: 8 c 3
9: 9 c 3