March 2019
Beginner to intermediate
448 pages
13h 14m
English
In this case, we will compare R against Rcpp (C++) for the following task. We will load a vector and a matrix. Our function will loop through each element of the vector, through each row, and through each row and column of that matrix, counting the number of instances where the elements of the matrix are greater than the ones in the vector.
#include <Rcpp.h>using namespace Rcpp;// [[Rcpp::export]]int bring_element (NumericVector rand_vector, NumericMatrix rand_matrix) {Rcout << "Process starting" << std::endl;int mcounter = 0;for (int q = 0; q < rand_vector.size();q++){ for (int x = 0; x < rand_matrix.rows();x++){ for (int y = 0; ...Read now
Unlock full access