2014-12-05 20 views

Antwort

33

können Sie versuchen,

library(lubridate) 
seconds_to_period(86400) 
#[1] "1d 0H 0M 0S" 

seconds_to_period(48000) 
#[1] "13H 20M 0S" 

Wenn Sie format benötigen

td <- seconds_to_period(86400) 
sprintf('%02d %02d:%02d:%02d', day(td), [email protected], minute(td), second(td)) 
#[1] "01 00:00:00" 

Wenn es für >99 Tage erstreckt,

td <- seconds_to_period(1e7) 
sprintf('%03d %02d:%02d:%02d', day(td), [email protected], minute(td), second(td)) 
#[1] "115 17:46:40" 
0

Dies funktioniert auch seconds.to.hms von kimisc mit, wenn auch nicht so elegant wie @ak Lauf Antwort:

library(kimisc) 
library(dplyr) 
library(stringr) 

HMS = seconds.to.hms(86400) 

HMS = seconds.to.hms(48000) 

HMS = seconds.to.hms(1e7) 

HMS %>% 
    str_extract("^\\d+") %>% 
    as.numeric() %>% 
    {paste(.%/%24, .%%24)} %>% 
    str_replace(HMS, "^\\d+", .) 

Ergebnis:

[1] "1 0:00:00" 

[1] "0 13:20:00" 

[1] "115 17:46:40" 
Verwandte Themen