R指定时间戳差异的单位

R specifying unit for diff of timestamps

在比较 POSIXct 值时如何指定要使用的单位?

例如,

times <- c("2015-04-20T07:45:00Z","2015-04-20T07:30:00Z","2015-04-20T07:45:00Z","2015-04-20T07:45:00Z","2015-04-20T08:00:00Z")
time <- as.POSIXct(times,format = "%Y-%m-%dT%H:%M:%SZ")
diff(time)

生产

Time differences in secs
[1] -900  900    0  900

知道如何以分钟为单位指定这个时间吗?

尝试difftime

 difftime(time[-1], time[-length(time)], unit='min')
?difftime

time1 - time2

difftime(time1, time2, tz,
         units = c("auto", "secs", "mins", "hours",
                   "days", "weeks"))