I have this type of data:
df <- data.frame(
Partcpt = c("B","A","B","C"),
aoi = c("ACA","CB","AA","AABC" )
)
I want to replace the individual letters in aoi with consecutive numbers unless the letters are duplicates, in which case the earlier replacement number should be repeated. Is there a regex solution to this? I'm open to other solutions as well.
The desired output is this:
Partcpt aoi
1 B 121
2 A 12
3 B 11
4 C 1123