I am trying to use sprintf
function to add leading "0" to character, and make all charaters the same length. However what I get is leading space.
My code:
a <- c("12","123", "1234")
sprintf("%04s",a)
[1] " 12" " 123" "1234"
What I tried to get:
[1] "0012" "0123" "1234"
The sprintf
manual says: "For characters, this zero-pads on some platforms and is ignored on others."
My version:
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 1.0
year 2014
month 04
day 10
svn rev 65387
language R
version.string R version 3.1.0 (2014-04-10)
nickname Spring Dance