I have this df
ID CODE
A 45676
B 87898
B 89998
A 45688
A 45556
I would like to get this df
ID CODE CODE_SUB
A 45676 76
B 87898 NA
B 89998 NA
A 45688 88
A 45556 56
CODE_SUB is last two characters from CODE with condition ID == A
I used this code
mutate(CODE_SUB = substr(which (df$ID == "A"), CODE , start= 4, stop= 5))
But
Error: Problem with mutate() input CODE_SUB.
x unused argument (CODE)