1

I tried TTR::EMA and TTR::WMA or other MA functions in TTR packages and I also tried qcc::ewma and qcc::ewmaSmooth, but none of them can deal with data with NA. I know Python pandas package has function pd.ewma. I may not know R well....can anybody know such function in R?

for example, in python:

a=pd.Series([1,4, np.nan, np.nan,1])
pd.ewma(a, span=2/0.01-1)

Out[137]: 
0    1.000000
1    2.507538
2    2.507538
3    2.507538
4    1.993177
dtype: float64

thanks

Karina
  • 15
  • 5
  • Anything here you might find useful? http://stackoverflow.com/questions/743812/calculating-moving-average-in-r – Roman Luštrik Nov 20 '15 at 22:35
  • Not an exact solution, but you could use the base function `filter` to apply any filter you want. You'd have to generate the weights manually, but that's not hard to do. – Alexey Shiklomanov Nov 20 '15 at 22:36
  • Just because a function "deals" with missing values, doesn't mean it's suitable for your application. Is it really okay to assume that there's no decay until the next non-missing value? – Joshua Ulrich Nov 20 '15 at 23:02
  • @RomanLuštrik i already know these packages but i think none of them have this capability... – Karina Nov 23 '15 at 20:49
  • @AlexeyShiklomanov i tried to do it manually but it was painful...that is why i am looking for a built-in function. – Karina Nov 23 '15 at 20:50
  • @JoshuaUlrich actually i did use pandas.ewma to achieve my goal but i just want to know if R has similar functions or not...for sure my data has missing value btw... – Karina Nov 23 '15 at 20:51

0 Answers0