Reputation:
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?
Upvotes: 2
Views: 55
Reputation: 13581
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"
Upvotes: 1
Reputation: 3188
Try sprintf()
instead
sprintf("G%02d", c(7:9, 10:14))
[1] "G07" "G08" "G09" "G10" "G11" "G12" "G13" "G14"
Upvotes: 7