2016-07-14 104 views

回答

1

一種方式做到這一點完全使用lubridate包:

library(lubridate) 

# Create sample interval 
> span <- interval(as.POSIXct("2000-01-01"), as.POSIXct("2016-01-01")) 
> span 
[1] 2000-01-01 PST--2016-01-01 PST 

> t <- as.period(span, unit="day") 
> t 
[1] "5844d 0H 0M 0S" 

> t/as.period(dweeks(1)) 
estimate only: convert durations to intervals for accuracy 
estimate only: convert to intervals for accuracy 
[1] 834.8571 
> 
0

我發現了一個更簡單的方法,而無需使用lubridate:

t1 <- as.POSIXct("2000-01-01") 
t2 <- as.POSIXct("2016-01-01") 
as.double(difftime(t2,t1,unit="weeks")) 

[1] 834.8571

+0

是的,這工程太。但從你的帖子來看,這聽起來像你只想使用lubridate軟件包,沒有別的。 – Koba

+0

是的,我最初認爲這將是最簡單的。 – ronnydw

相關問題