<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi Kevin,<div><br></div><div>I just had a quick look, at RcppRoll and noticed that almost all of the results have a single value as an output, and was wondering if it was possible to be able to get more than one output per loop…</div><div><br></div><div>to give a quick example, i would be grateful if you could show me how the following could be converted using rollit(). Hopefully this is possible.</div><div><br></div><div><div>n <- 50</div><div>m <- 3</div><div>mu <- 0.0001</div><div>sigma <- 0.003</div><div><br></div><div>require(xts)</div><div>x <- xts(matrix(rnorm(n*m,mu,sigma),ncol=m),Sys.Date()-c(n:1))</div><div><br></div><div>foo <- function(x){</div><div>  c(mean(x),sd(x))</div><div>}</div><div><br></div><div>foo1 <- function(x){</div><div>  y <- x[,1]+(3*x[,2])+(log(abs(x[,3])))</div><div>  tmp <- data.frame(cbind(y=y,x=x))</div><div>  colnames(tmp) <- c("y","a","b","c")</div><div>  c(sum(y), sd(y), coef(lm(y~a+b+c,data=tmp)))</div><div>}</div><div><br></div><div>rollapply(x,width=10,function(y){foo(y)},by.column=FALSE)</div><div>rollapply(x,width=10,function(y){foo1(y)},by.column=FALSE)</div></div><div><br></div><div>Thanks</div><div><br></div><div>HLM</div><div><br></div><div><div>On 26 Feb 2014, at 16:57, Kevin Ushey <<a href="mailto:kevinushey@gmail.com">kevinushey@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">And, I'm the RcppRoll developer -- I haven't touched the package in a while so let me know if you run into any rough corners / have ideas for improvements. The package is still pretty 'young' and not quite battle-worn yet.<div>
<br></div><div>Thanks,</div><div>Kevin</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Feb 26, 2014 at 8:36 AM, Hideyoshi Maeda <span dir="ltr"><<a href="mailto:hideyoshi.maeda@gmail.com" target="_blank">hideyoshi.maeda@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Didn’t even know it existed! will take a look now. Thanks<br>
<div class="HOEnZb"><div class="h5">On 26 Feb 2014, at 16:35, Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</a>> wrote:<br>
<br>
><br>
> On 26 February 2014 at 16:23, Hideyoshi Maeda wrote:<br>
> | Hi Rcpp devel list,<br>
> |<br>
> | One of the functions I like to use is zoo’s rollapply() function. However sometimes this can be slow as it is basically a long loop using mapply.<br>
> |<br>
> | Given how fast loops are in C++ this seems like this would be the perfect thing to covert into C++, BUT, one of the benefits of rollapply, is that it is flexible and you can put in any R custom function you like. I think there are some functionality in Rcpp that allow you to carry out custom R functions, but not sure what it is or if it would be helpful as you might have to recursively keep calling R each time it need the custom function in the loop.<br>

> |<br>
> | So I guess my question is 1) is there an existing implementation that has converted rollapply to C++ and 2) if not, then given the desired flexibility of using custom functions in rollapply, would converting it into C++ code be worthwhile? 3) if it would be worthwhile, then what should I be researching to be able to get custom functions into Rcpp/C++?<br>

><br>
> Have you looked at RcppRoll yet?  See<br>
><br>
>   <a href="http://cran.r-project.org/web/packages/RcppRoll/index.html" target="_blank">http://cran.r-project.org/web/packages/RcppRoll/index.html</a><br>
><br>
> Dirk<br>
><br>
> --<br>
> Dirk Eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com/" target="_blank">http://dirk.eddelbuettel.com</a><br>
<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</div></div></blockquote></div><br></div>
</blockquote></div><br></body></html>