Skip to content

convert one digit numbers to two digits one

4 messages · Alaios, David Winsemius, Bert Gunter +1 more

#
On Nov 6, 2013, at 8:25 AM, Alaios wrote:

            
?sprintf  # other options are linked from that page.
Sigh.
#
(Assuming I understand) tons of ways of doing this.

So I'll just point out the
?nchar
function, which you can use to count characters in your tail end and
paste a "0" if there's only one, e.g. via ifelse() .

-- Bert
On Wed, Nov 6, 2013 at 8:25 AM, Alaios <alaios at yahoo.com> wrote:

  
    
#
On Nov 6, 2013, at 10:25 AM, Alaios <alaios at yahoo.com> wrote:

            
This is an example where using ?sprintf gives you more control:
[1] "12:03"
[1] "09:03"


The syntax '%02d' tells sprintf to print the integer and pad with leading zeroes to two characters where needed.

Regards,

Marc Schwartz