[Rcpp-devel] Push back to a matrix

Davor Cubranic cubranic at stat.ubc.ca
Tue Sep 6 18:55:31 CEST 2011


On September 5, 2011 11:11:46 AM Noah Silverman wrote:
> Nice,
> 
> But, how can I copy to the Rcpp::NumericMatrix column?
> 
> This fails:
> std::vector<double> data1;
> // do stuff to populate data1
> 
> Rcpp::NumericMatrix output(data1.size(), 6);
> std::copy(data1.begin(), data1.end(), output(_,0) );
> 
> 
> I'm probably referencing the matrix column incorrectly, but can't find any
> documentation for Rcpp on how to do this correctly.

That's because in this case you're using standard C++ mechanisms and there is 
nothing particularly special about Rcpp. So you should instead have a look at 
documentation on STL, in particular how algorithms (copy) work on containers 
(vectors) using iterators (begin/end), as well as operations on iterators and 
how they're similar to pointers.

Davor


More information about the Rcpp-devel mailing list