Description Details Author(s) Examples
Example on how to use a NumericVector and manipulate it with the STL.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | NumericVector orig ; // from R
NumericVector vec(orig.size()); // create a target vector of the same size
// we could query size via
// int n = vec.size();
// and loop over the vector, but using the STL is so much nicer
// so we use a STL transform() algorithm on each element
std::transform(orig.begin(), orig.end(), vec.begin(), sqrt_double );
List result = List::create(
Named( "result" ) = vec,
Named( "original" ) = orig
) ;
return result ;
|
As shown in the example section, provided the seed is reset, the exact same draws can be obtained in R itself – which is important for reproducibility.
Dirk Eddelbuettel and Romain Francois
1 | RcppNumericVectorExample( seq(1,9)^2 )
|
$result
[1] 1 2 3 4 5 6 7 8 9
$original
[1] 1 4 9 16 25 36 49 64 81
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.