在XTS中使用erige.ly与平均函数应用给出不同的结果(聚合和每列)
使用R和功能,我很新,所以请在您的答案中考虑到这一点。
我有数据波纹管,当我尝试使用该时期获得两个列的平均值时。与函数 + na.rm = true一起使用,因为我在真实数据中具有na,我只得到汇总均值而不是列的均值示例bellow。 问题是如何获得每列的含义并使用na.rm = true 谢谢
zoo.data_1 <- zoo(rnorm(31)+10,as.Date(13514:13744,origin="1970-01-01"))
zoo.data_2 <- zoo(rnorm(20)+10,as.Date(13514:13744,origin="1970-01-01"))
zoo.data <- merge(zoo.data_1,zoo.data_2)
ep <- endpoints(zoo.data,'month')
period.apply(zoo.data, INDEX=ep, FUN=function(x) mean(x,na.rm = TRUE))
period.apply(zoo.data, INDEX=ep, FUN=mean)
=“ https://i.sstatic.net/nbbix.png” alt =“在此处输入映像
”
..... .....
I am quite new using R and Function so please take this in account in your answer.
I have the data bellow and when I try to get the mean for both columns using the period.apply with FUNCTION + na.rm = TRUE since I have NA in the real data I get only the aggregate mean and not the column mean as in the example bellow.
The question is how can I get the per column mean and using na.rm = TRUE
Thanks
zoo.data_1 <- zoo(rnorm(31)+10,as.Date(13514:13744,origin="1970-01-01"))
zoo.data_2 <- zoo(rnorm(20)+10,as.Date(13514:13744,origin="1970-01-01"))
zoo.data <- merge(zoo.data_1,zoo.data_2)
ep <- endpoints(zoo.data,'month')
period.apply(zoo.data, INDEX=ep, FUN=function(x) mean(x,na.rm = TRUE))
period.apply(zoo.data, INDEX=ep, FUN=mean)
So what I need is format (per column) bellow but with na.rm = TRUE
.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是使用lambda表达式,而是指定参数,并且应该在此处使用
,则使用基于数据的
class
的不同方法。eange
如果我们检查Mean.zoo
,因此,“ x”需要
coredata
的应用,这在fun
中可能是不可能的,而我们可以使用
Instead of using a lambda expression, specify the argument and it should work
Here, the
mean
use a different method based on theclass
of the data i.e.If we check
mean.zoo
,Therefore, the 'x' requires application of
coredata
, which may not be possible within theFUN
whereas we can use