[Rcpp-devel] Push back to a matrix

Noah Silverman noahsilverman at ucla.edu
Mon Sep 5 18:31:54 CEST 2011


Hi,

Using Rcpp through inline.

I want to return a matrix, but I don't know the size beforehand.  (My code loops through a large data set accumulating certain statistics.)

With a NumericVector, I can use push_back() to just add values to the end of the vector as they occur.  Is there similar functionality for a NumericMatrix?

Alternately, I could store all my generated statistics in several vectors (6-7) and then, when complete with my loop, glue them together into a matrix.  But, this seems inefficient.


Here is a rough example of what I'm trying to do.

------------------------------
int n = inputData.size();

Rcpp::NumericMatrix output;

for(int i=0; i != n; i++){
	// generate some stats with a lot of code not shown
	
	foo = mean(stuff);
	bar = min(stuff);
	baz = max(stuff);
	// etc...
	
	output.push_back(foo, bar, baz);

)

return output;
-------------------------------


--
Noah Silverman
UCLA Department of Statistics
8117 Math Sciences Building #8208
Los Angeles, CA 90095

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110905/91fd89fb/attachment.htm>


More information about the Rcpp-devel mailing list