#includeusing namespace Rcpp; // [[Rcpp::export]] int get_nrow(NumericMatrix mat) { return mat.nrow(); } /*** R mat <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2) get_nrow(mat) */
#includeIn this example, we define a function called "check_rows_equal" that takes two NumericMatrices as input and returns true if they have the same number of rows, and false otherwise. We then use this function in R to check if two matrices have the same number of rows. Overall, NumericMatrix is a useful class in the Rcpp package library for working with numerical data in C++. The nrow function is just one of the many functions that can be used to manipulate matrices efficiently.using namespace Rcpp; // [[Rcpp::export]] bool check_rows_equal(NumericMatrix mat1, NumericMatrix mat2) { return mat1.nrow() == mat2.nrow(); } /*** R mat1 <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2) mat2 <- matrix(c(7, 8, 9, 10, 11, 12), nrow = 2) check_rows_equal(mat1, mat2) */