Graphics Reference
In-Depth Information
timeHM_formatter(c( 0 , 50 , 51 , 59 , 60 , 130 , 604 ))
"0:00" "0:50" "0:51" "0:59" "1:00" "2:10" "10:04"
To convert to HH:MM:SS format, you can use the following formatter function:
timeHMS_formatter <- function
function (x) {
h <- floor(x / 3600 )
m <- floor((x / 60 ) %% 60 )
s <- round(x %% 60 ) # Round to nearest second
lab <- sprintf( "%02d:%02d:%02d" , h, m, s) # Format the strings as HH:MM:SS
lab <- sub( "^00:" , "" , lab)
# Remove leading 00: if present
lab <- sub( "^0" , "" , lab)
# Remove leading 0 if present
return
return (lab)
}
Running it on some sample numbers yields:
timeHMS_formatter(c( 20 , 3000 , 3075 , 3559.2 , 3600 , 3606 , 7813.8 ))
"0:20"
"50:00"
"51:15"
"59:19"
"1:00:00" "1:00:06" "2:10:14"
See Also
See Converting a Time Series Object to Times and Values for information about converting time
series objects to data frames.
Search WWH ::




Custom Search