The NumericMatrix class is a C++ class designed to represent two-dimensional matrices of numeric values. It provides a convenient and efficient way of manipulating large sets of data in a matrix format.
Here is an example code snippet using NumericMatrix:
```c++
#include
// [[Rcpp::export]]
Rcpp::NumericMatrix myFunction(Rcpp::NumericMatrix m) {
// create a new matrix with the same dimensions as input matrix
Rcpp::NumericMatrix result(m.nrow(), m.ncol());
// Iterate over each element of the input matrix and perform some operation
for(int i = 0; i < m.nrow(); i++) {
for(int j = 0; j < m.ncol(); j++) {
result(i, j) = m(i, j) * 2.0;
}
}
return result;
}
```
This code defines a function called `myFunction` that takes a NumericMatrix as input and returns a new matrix with each element multiplied by 2.0. The code uses the NumericMatrix class provided by the Rcpp package, which allows seamless integration of C++ code with R.
Therefore, the package library for NumericMatrix is Rcpp.
C++ (Cpp) NumericMatrix::begin - 30 examples found. These are the top rated real world C++ (Cpp) examples of NumericMatrix::begin extracted from open source projects. You can rate examples to help us improve the quality of examples.