1

我有一个像这样的 chron 对象:

 t <- as.chron("06/01/13 01:00:00", "%m/%d/%y %H:%M:%S") 

我想将它从原点转换为秒,原点是:

 or <- "06/01/13 00:00:00"

所以我想要的是对象 t 变成:

 t <- 3600

非常感谢朱利亚

4

1 回答 1

1

只需使用difftime()

R> library(chron)
R>  t <- as.chron("06/01/13 01:00:00", "%m/%d/%y %H:%M:%S") 
R> or <- as.chron("06/01/13 00:00:00", "%m/%d/%y %H:%M:%S") 
R> difftime(t, or)
Time difference of 1 hours
R> 

或以您想要的单位:

R> difftime(t, or, unit="secs")
Time difference of 3600 secs
R> as.numeric(difftime(t, or, unit="secs"))
[1] 3600
R> 

顺便说一句,您可能想要使用whichPOSIXct而不是chronwhich difftime()converts to 无论如何。见help(DateTimeClasses)

于 2014-01-10T17:44:20.840 回答