I have a vector that looks like
> inecodes [1] \"01001\" \"01002\" \"01049\" \"01003\" \"01006\" \"01037\" \"01008\" \"01004\" \"01009\" \"01010\" \"01
library(stringr) for(code in inecodes) { ix <- which(str_detect(pob, code)) pob[ix] <- unlist(str_split(pob, "-", 2))[2] }