Hello I am new to Rcpp, and am looking to translate some for loops in R to C++ 
using Rcpp, but I am sort of stuck at the first hurdle, as the simple tutorials 
do not really seem to deal with xts structures.

The closest I found for some help online was found here 
(http://gallery.rcpp.org/articles/accessing-xts-api/) but that seems to only 
give xts outputs rather than taking in xts inputs. Below is a mock example of R 
code that has a function and takes an xts object as an input and gives an xts 
object as an output.

toy.xts <- function(xtsobj,val.vec){
  xtsobj1 <- xtsobj
  for(i in 1:nrow(xtsobj1)){
    if((i %/% 3)==3 ){
      xtsobj1[i,"B"] <- val.vec[1]
    } else {
      xtsobj1[i,c("C","D")] <- val.vec+1
    }
  }
  xtsobj1
}

tmp.xts <- xts(matrix(c(1:500),ncol=5),Sys.Date()-c(1:100))
colnames(tmp.xts) <- LETTERS[1:5]
tmp.vec <- c(0.4,0.9)
toy.xts(tmp.xts,tmp.vec)

I know that this isn’t exactly the use case for converting R code, to C++, but 
I’m not too sure where to start when dealing with these different/non-simple 
structures as inputs. Apologies if this is very simple. 

Would the RcppXts packages help at all? It doesn’t seem to have a huge number 
of functions, and am not too sure how to use it?

Thanks in advance

HLM
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to