[Rcpp-devel] a variable for loop

Amina Shahzadi aminashahzadi at gmail.com
Wed Dec 14 03:51:48 CET 2016

Hello Friends and Prof. Dirk

I am pasting here a code which has a for loop depending on another for
I am getting zeros for cube c. I tried and searched a lot but did not get
an example of this type. Would you please help in this regard?

#include <RcppArmadillo.h>
using namespace Rcpp;
using namespace RcppArmadillo;
using namespace arma;

arma::cube  exam(arma::vec a,  arma::mat b)
  int m = a.size();
  int n = b.n_rows;
  arma::cube c = zeros<cube>(n, m, n);
  for(int i=0; i<n; i++) {
    for(int j=0; j<m; j++) {
      for(int k=0; k<i; k++) {
          if(k==0) {
            c(i, j ,k) = c(i, j, k) + b(i, j);
            c(i, j, k) = c(i, j, k) +  c(i-1, j, k) *b(i, j);
  return c;

Thank You
*Amina Shahzadi*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20161214/b6645368/attachment.html>

More information about the Rcpp-devel mailing list