开发者

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

开发者 https://www.devze.com 2023-04-09 12:34 出处:网络
When running the following: wavData = ddply(wavData, c(\"primary\", \"int开发者_运维百科erference\", \"label\"), transform,

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

精彩评论

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