#includeusing namespace Rcpp; // [[Rcpp::export]] NumericVector createVector() { NumericVector v = NumericVector::create(1.1, 2.2, 3.3); return v; } // [[Rcpp::export]] void printVector(NumericVector v) { for(int i=0; i
In this example, we create a NumericVector with values 1.1, 2.2, and 3.3 using the `create` function. We then print the values of this vector using a loop in the `printVector` function.
Example 2: Adding two NumericVectors#includeIn this example, we create a function that takes two NumericVectors as arguments and adds them together using the `+` operator. We then return the resulting NumericVector. Overall, NumericVector is a convenient and efficient class in the Rcpp package library that is useful for handling and manipulating numerical vectors in R code.using namespace Rcpp; // [[Rcpp::export]] NumericVector addVectors(NumericVector v1, NumericVector v2) { NumericVector v3 = v1 + v2; return v3; }