【发布时间】:2011-11-25 08:52:11
【问题描述】:
在R 中,我有一个xts 对象列表,我想计算列表中所有项目的时间索引范围。但是我找不到一种流畅的方法,它会不断丢失对象的类并变成原始数字向量。
例如(我的列表名为states,它的索引是格林威治标准时间POSIXct):
> c(min(sapply(states, start)), max(sapply(states, end)))
[1] 1252714110 1315785360
> range(sapply(states, function(x) range(index(x))))
[1] 1252714110 1315785360
将这些转换回POSIXct 很麻烦,我是这样做的:
minmax <- range(sapply(states, function(x) range(index(x))))
epoch <- as.POSIXct(0, origin="1970-01-01", tz="GMT")
rg <- as.POSIXct(minmax, origin="1970-01-01", tz="GMT")
建议!
【问题讨论】: