To format numbers as fixed width with leading zeros added, you can use the sprintf() function from the base package.
Basic syntax for sprintf() is:
sprintf(fmt, ...)
Where,
fmt
a character vector of format strings, each of up to 8192 bytes.
...
values to be passed into fmt. Only logical, integer, real and character vectors are supported, but some coercion will be done: see the ‘Details’ section. Up to 100.
In your case:
a <- seq(1,101,25)
b <- paste("name",a, sep = "_")
sprintf("name_%03d", a)
[1] "name_001" "name_026" "name_051" "name_076" "name_101"
You can also use the paste function along with formatC as follows:
paste("name", formatC(a, width=3, flag="0"), sep="_")
[1] "name_001" "name_026" "name_051" "name_076" "name_101"