0

what is the more elegant way of just using sprintf without the gsub for this line of code?

gsub(" ","0",sprintf("%2.d", 0:15))
[1] "00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "10" "11" "12" "13" "14" "15"

i.e. I want the zeros infront of the single digit numbers...as output as characters.

h.l.m
  • 13,015
  • 22
  • 82
  • 169

1 Answers1

3

Use a 0 in the format string to pad with leading zeros instead of spaces: sprintf("%02d", 0:15)

flodel
  • 87,577
  • 21
  • 185
  • 223
nneonneo
  • 171,345
  • 36
  • 312
  • 383