[R] convert one digit numbers to two digits one

David Winsemius dwinsemius at comcast.net
Wed Nov 6 17:32:13 CET 2013


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

> Hi all,
> the following returns the hour and the minutes
> 
> paste(DataSet$TimeStamps[selectedInterval$start,4], DataSet$TimeStamps[selectedInterval$start,5],sep=":")
> [1] "12:3"
> 
> the problem is that from these two I want to create a time stamp so 12:03. The problem is that the number 3 is not converted to 03. Is there an easy way when I have one digit integer to add a zero in the front? Two digits integers are working fine so far, 12:19, or 12:45 would appear correctly
> 

?sprintf  # other options are linked from that page.

> 
> 	[[alternative HTML version deleted]]
Sigh.
-- 

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list