I have a list of lines like this:
f<-c("CC 982","RX 112","TR 002","FF 1328")
I need to add a start 0, like a function str_pad, at the beginning of the numeric part to go to the following:
"CC 0982" "RX 0112" "TR 0002" "FF 1328"
I have currently tried to use sub
sub('(.{2})(.{1})(.{3})', "\\1\\20\\3", f)
Close enough, but I don't want the leading 0 if the number string has 4 digits. What is the solution here? Thanks you
source
share