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)))
精彩评论