Skip to content
Prev 2258 / 10988 Next

[Rcpp-devel] A Question about List of List of Vecotrs

Le 05/05/11 22:08, Fatemeh Riahi a ?crit :
Hi,

Your code pretty much litterally translates itself to C++.

require( Rcpp )
require( inline )

fx <- cxxfunction( signature( n_ = "integer", m_ = "integer" ), '

     int n = as<int>( n_ ), m = as<int>( m_ ) ;

     Rcpp::List out(n) ;
     for( int i=0; i<n; i++){
         Rcpp::List x(m) ;
         for( int j=0; j<m; j++){
             x[j] = rep( 0, m ) ;
         }
         out[i] = x ;
     }
     return out ;
', plugin = "Rcpp" )

fx( 5, 4 )

Hope this helps,

Romain