gpt4 book ai didi

r - R align.time/aggregate 中的错误?

转载 作者:行者123 更新时间:2023-12-04 15:44:25 26 4
gpt4 key购买 nike

我有一个时间序列 x:

dput(x)
structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28.8, 0, 0,
0, 0, 0, 0, 0, 0), index = structure(c(1193524740, 1193525340,
1193525940, 1193526540, 1193527140, 1193527740, 1193528340, 1193528940,
1193529540, 1193530140, 1193530740, 1193531340, 1193531940, 1193532540,
1193533140, 1193533740, 1193534340, 1193534940, 1193535540, 1193536140,
1193536740, 1193537340), class = c("POSIXct", "POSIXt")), class = "zoo")

我聚合到 1 小时
as.xts(aggregate(x, align.time(index(x), 60*60))) 
[,1]
2007-10-28 00:00:00 0.0
2007-10-28 01:00:00 0.0
2007-10-28 01:00:00 28.8
2007-10-28 02:00:00 0.0
2007-10-28 03:00:00 0.0

如您所见,我得到了重复的“2007-10-28 01:00:00”。

我想知道这是一个错误还是我做错了什么?

最佳答案

这很可能不是错误,而是您所在地区的问题...

library(xts)

## Loading required package: zoo
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric

library(zoo)
v <- rep(0,22)
v[14] <- 28.8

d <- c(1193524740, 1193525340, 1193525940, 1193526540, 1193527140, 1193527740, 1193528340, 1193528940, 1193529540, 1193530140, 1193530740, 1193531340, 1193531940, 1193532540, 1193533140, 1193533740, 1193534340, 1193534940, 1193535540, 1193536140, 1193536740, 1193537340)
orig <- "1970-01-01 00:00.00 UTC"

# Output with duplicate...
x <- zoo(v, as.POSIXct( d, tz="Europe/London", origin=orig) )
as.xts(aggregate(x, align.time(index(x), 60*60)))

## [,1]
## 2007-10-28 00:00:00 0.0
## 2007-10-28 01:00:00 0.0
## 2007-10-28 01:00:00 28.8
## 2007-10-28 02:00:00 0.0
## 2007-10-28 03:00:00 0.0

# Output with duplicate...
x <- zoo(v, as.POSIXct( d, tz="UTC", origin = orig) )
as.xts(aggregate(x, align.time(index(x), 60*60)))

## [,1]
## 2007-10-27 23:00:00 0.0
## 2007-10-28 00:00:00 0.0
## 2007-10-28 01:00:00 28.8
## 2007-10-28 02:00:00 0.0
## 2007-10-28 03:00:00 0.0

?Sys.timezone和 SO info页面为
标签;特别是 R 使用的 Olson 时区数据库信息,以及 summary of answers夏令时和时区最佳实践 问题。

关于r - R align.time/aggregate 中的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22672495/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com