[英]How to copy Rcpp::DateVector to std::vector<boost::gregorian::date>
I want to pass data from zoo
object into my program in C++ using Rinside
, but I don't know how to pass date. 我想使用
Rinside
将数据从zoo
对象传递到C ++中的程序中,但是我不知道如何传递日期。
Here is an example 这是一个例子
RInside R(argc, argv); // create an embedded R instance
std::string cmd = "suppressMessages(library(zoo)); "
"z <- zoo(rnorm(10), as.Date('2000-01-01') - 0:10);";
R.parseEvalQ(cmd);
std::vector<double> v = Rcpp::as< std::vector< double > >(R.parseEval("coredata(z)"));
Rcpp::DateVector d ( (SEXP) R.parseEval("index(z)") );
std::vector<boost::gregorian::date> dt = //How assign d to dt ?
You need simple converters such as this in the RcppBDT package : 在RcppBDT软件包中,您需要像这样的简单转换器:
template <> boost::gregorian::date as( SEXP dtsexp ) {
Rcpp::Date dt(dtsexp);
return boost::gregorian::date(dt.getYear(), dt.getMonth(), dt.getDay());
}
which you then need to vectorise. 然后您需要向量化。 Alternative, maybe use integer vector (with days since epoch).
或者,可以使用整数向量(自历元起算的天数)。
Edit: An there is an entire Rcpp Gallery post devoting to this, as well as several more dealing in related topics. 编辑:有一个完整的Rcpp Gallery帖子专门讨论此内容,以及其他一些涉及相关主题的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.