I am trying to convert integer into string by using as.character
function in R. But I need the string to be always of length 3. So 7
will get converted into 007
, 10
into 010
and so on. I am wondering if there is some simple modification of as.character
(or any other built-in R routine) which will quickly accomplish this.
See ?sprintf
:
R> sprintf("%03d", c(7, 10))
[1] "007" "010"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With