Skip to content
Back to formatted view

Raw Message

Message-ID: <CAJJHHA_CW1vQP4UfnYNYEA2gvataSvJyWrKS+E9rtn-eK9ukbg@mail.gmail.com>
Date: 2013-03-01T16:15:43Z
From: stat quant
Subject: [Rcpp-devel] Can I fill a matrix row by row with std<vector> (or similar)

Hello list,
I have several std::vector<double> in a STL container and would like to
fill a Rcpp::NumericMatrix row by row with them, is there an easy way to do
it, or should I iterate over all elements as in usual C++?
I saw the `_` in this post on SO but I think it has a different purpose.
cCode <- '
    double v_value[] = {1.1,2.4};
    vector<double> v(v_value, v_value + sizeof(v_value)/sizeof(double));
    NumericMatrix m(3,2);

    //Here is what I was hoping for
    //for(int i=0; i<3; i++){
    // m(i,_) = v;
    //}

    return m;
';
R)
fillMat <- cxxfunction(signature(), includes='using namespace std;',
plugin="Rcpp", body=cCode)

Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130301/95f4cda9/attachment.html>