<div dir="ltr"><div>This is not a Rcpp solution but be advise that as long as your function 
"ma" do not require values on previous lines, you might want to look at 
the data.table package. This package provides ultra fast operations on 
data.frames.<br></div>Off course nothing prevents you from writing "ma" in C/C++ and to use data.table to apply the function quickly and to insert the new data into the data.table by reference<br></div>