2

I cannot figure out how to do this in one run

G07, G08, G09, G11, G12, G13, G14

so I know how to do the first one

paste0("G0",7:9)

i also know how to do the second part

paste0("G",10:14)

All what I could think of is to combine them by rbind

rbind (paste0("G0",7:9),paste0("G",10:14))

this is not a good way and I am looking to see if you can guide me to find a better way?

2 Answers2

7

Try sprintf() instead

sprintf("G%02d", c(7:9, 10:14))

[1] "G07" "G08" "G09" "G10" "G11" "G12" "G13" "G14"
Vlo
  • 3,168
  • 13
  • 27
1

You could also use stringr::str_pad for this

paste0("G", stringr::str_pad(7:14, 2, side="left", pad="0"))
# "G07" "G08" "G09" "G10" "G11" "G12" "G13" "G14"
CPak
  • 13,260
  • 3
  • 30
  • 48