I am trying to add "S00", "S0", or "S" to strings in tst if they are 1 or 2 or 3 times long, respectively. So the outcome would be S004,S008,S009,S022,S051,...,S753.
been trying with ifelse
and grepl
but it was not successful:
tst <- as.character(c(4,8,9,22,51,56,57,12,15,150,147,852,654,753))
ifelse(grepl("[0-9]{1} ", tst), paste("S00", tst,sep = ""),
ifelse(grepl("[0-9]{2} ", tst), paste("S0", tst,sep = ""), "S"))