XTS Apply Family and a Multi Column XTS?

醉酒当歌 提交于 2019-12-04 09:36:36

You could simply use colMeans to take the mean of every column:

library(quantmod)
getSymbols("SPY")
spy1 <- apply.weekly(SPY, colMeans)

You could also define an arbitrary function that uses apply over the columns of your object:

spy2 <- apply.weekly(SPY, function(x) apply(x,2,mean))
identical(spy1,spy2)
# [1] TRUE
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!