I have created a dataframe with a group column and an individual identifier which incorporates the group name and a number formatted to a standardised three digit code:
library(stringr)
group = rep(c("A", "B", "C"), each = 3)
df <- data.frame(group, indiv = paste(group, str_pad(1:9, pad = 0, width = 3 , "left"), sep = ""))
All well and good, but how would I go about resetting the individual identifier each time there is a new prefix, for this ideal result:
df2 <- data.frame(group, indiv = c("A001", "A002", "A003",
"B001", "B002", "B003",
"C001", "C002", "C003"))