title: Apply a function rowwise in Rcpp/RcppArmadillo
body: <p>I have a function which takes a vector as input and outputs a scalar and I want to apply this function to a number of observations. The data is structured in a matrix (rows are the number of observations and columns the variables) and the function is:</p>
  
  <pre><code>// [[Rcpp::export]]
  double gaussianweight(arma::vec x, arma::mat H) {
    double c       = std::pow(2 * arma::datum::pi, -0.5 * x.n_rows);
    double s       = std::pow(arma::det(H), -1);
    arma::mat Hinv = arma::inv(H);
  
    return(c * s * std::exp(-0.5 * arma::dot(Hinv * x, Hinv * x)));
  }
  </code></pre>
  
  <p>to every <em>row vector</em> of a <code>arma::mat X</code>. How would I do that efficiently? A loop that lopps over the rows of X or are there better solutions? I use R for the most time and really got used to avoid loops whenever it is possible. I tried the <code>.each_row()</code> operations but had no luck... </p>