RcppNumericVectorExample: Rcpp NumericVector example

Description Details Author(s) Examples

View source: R/RcppVectorExample.R

Description

Example on how to use a NumericVector and manipulate it with the STL.

Details

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
    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 );

    return List::create(Named("result") = vec, 
                        Named("original") = orig);
  

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.

Author(s)

Dirk Eddelbuettel and Romain Francois

Examples

1


RcppExamples documentation built on May 19, 2017, 10:12 p.m.
Search within the RcppExamples package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs in the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.