开发者

Allowing WMA (from TTR package) to return original value when fewer than N points

When running the following:

wavData = ddply(wavData, c("primary", "int开发者_运维百科erference", "label"), transform, 
                value = WMA(value,3,wts=1:3))

Some of the resulting groupings made by ddply do not have 3 points in them, thus I get the following error:

Error in WMA(value, 3, wts = 1:3) : Invalid 'n'

Question: How can I allow WMA to return the ORIGINAL values when n<3, and not crash?


How about using ifelse?

wavData = ddply(wavData, c("primary", "interference", "label"), transform, 
            value = ifelse(length(value) < 3, value, WMA(value,3,wts=1:3)))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜