I am using Rcpp for analysis of XTS data and get its time index by using the following rcpp code:
#include <Rcpp.h>
using namespace Rcpp;
using namespace std;
// [[Rcpp::export]]
DatetimeVector xtsIndex(NumericMatrix X)
{
DatetimeVector v(NumericVector(X.attr("index")));
return v;
}
DatetimeVector tmpindexDaily = xtsIndex(askDailymat); // Get xts index to Rcpp vector
It turns out this conversion takes 2 ms to execute on a certain set of data were I only need time index, without this code, it takes less that 100 microseconds. Is there any way to better optimize the conversion or to avoid it entirely.