使用“百分比标准”将包括小时数据的NA转换为每日和每月数据

时间:2019-04-21 12:08:19

标签: r xts

我有一个每小时xts的数据,并希望将其转换为每日和每月的数据;但我的数据具有NA,我希望25%的标准有效。(如果系列中的NA百分比大于25%,则该系列假设为NA。)

为此,我尝试使用“ percentCriteria”,“ endpoints”和“ period.apply”命令;但是他们总是出错。我该如何解决这个问题?

getMeanBy <- function(ts, on, percentCriteria=TRUE)
ep <- endpoints(ts, on = "days")
per <- Mode(ep[2:length(ep)] - ep[1:(length(ep)-1)])
x <- if(percentCriteria)
period.apply(ts, INDEX=ep, FUN=mymean, per) else # with 25% criteria
period.apply(ts, INDEX=ep, FUN=mean, na.rm=T) # with na.rm=T criteria

0 个答案:

没有答案