speeding up a for loop on a rolling window

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

speeding up a for loop on a rolling window

I have the following loop that I would like to speed up.

I have looked at RcppRoll, which seems the best option in my case. However I
am unfamiliar with c++ and unable to write a function in c++ that replaces

Thank you so much in advance for any help on this!!!

minQCalc <- function(x, length.window = 250, ...){
s.index <- length.window:dim(x)[1]
out.vec <- rep(NA, length(s.index))

for(s in s.index){
    x.sub <- x[(s - length.window + 1):s, ]
    out.vec[match(s, s.index)] <- QCalc(x.sub, ...)

out.min <- min(out.vec)

QCalc <- function(x, method = "quantile"){

alpha <- 0.99
alpha.tilde <- 0.974234518211730

if(method == "quantile"){

    out <- quantile(x,  alpha)

}else if(method == "ETL"){

  qq.alpha.tilde <- sort(x)[ceiling((1 - alpha.tilde)*length(x))]  
  out <- mean(x[x <= qq.alpha.tilde])
}else{stop("quantile unknown")} return(out)}

Sent from: http://r.789695.n4.nabble.com/datatable-help-f2315188.html
datatable-help mailing list
[hidden email]