求可扩展时间序列中多个观测值的平均值

Find the mean of multiple observations in an extensible time series

我有一个在特定日期有多个表演的 xts:

                    Performance
2004-05-31        -7.478589e-03
2004-06-30         1.565250e-02
2004-06-30         1.372764e-02
2004-07-30        -1.558922e-03
2004-07-30        -1.451943e-02
2004-07-30        -3.829991e-02
2004-08-31        -4.456728e-03
2004-08-31        -1.547637e-03
2004-08-31         1.901513e-02

我想得到一个新的时间序列或数据帧,没关系,用每个日期索引的方法:

                    Performance
2004-05-31        -7.478589e-03
2004-06-30         1.469007e-02 (mean of both 2004-06-30 observations)
2004-07-30        -5.225589e-03 (mean of three 2004-07-30 observations)
... 

我查看了 xts 作弊文件和互联网,没有发现任何相似之处。有人知道我可以使用什么功能吗?非常感谢您的宝贵时间。

一个选项是按 tapply 中的 index 分组并得到 mean

tapply(xt1, index(xt1), FUN = mean)
#  2004-05-31   2004-06-30   2004-07-30   2004-08-31 
#-0.007478589  0.014690070 -0.018126087  0.004336922 

apply.daily

library(xts)
apply.daily(xt1, mean)
#              [,1]
#2004-05-31 -0.007478589
#2004-06-30  0.014690070
#2004-07-30 -0.018126087
#2004-08-31  0.004336922

数据

xt1 <- structure(c(-0.007478589, 0.0156525, 0.01372764, -0.001558922, 
-0.01451943, -0.03829991, -0.004456728, -0.001547637, 0.01901513
), .Dim = c(9L, 1L), index = structure(c(1085961600, 1088553600, 
1088553600, 1091145600, 1091145600, 1091145600, 1093910400, 1093910400, 
1093910400), tzone = "UTC", tclass = "Date"), class = c("xts", 
"zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC")