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
  • 12,265
  • 18
  • 78
  • 162

1 Answers1

3

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

flodel
  • 85,263
  • 19
  • 176
  • 215
nneonneo
  • 162,933
  • 34
  • 285
  • 360