I am trying to implement the following code in C++ and call from R using the library Rcpp. Obviously, this code is much faster than writing in R alone. I was wondering if th