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