title: Extract every k-th column of arma::mat matrix in rcpp
body: <p>I was struggling with subsetting columns of a matrix of class arma::mat. </p>
  
  <p>Let's say <code>arma::mat X</code> is given, and I tried to create a vector of indices <code>IDX</code>, in order to do <code>X.cols(IDX)</code>. Especially, the index vector has every k-th integer from 1 to p (dimension of <code>X</code>). For example, one may be interested in every even columns <code>IDX=[2,4,6,8, ...]</code>.</p>
  
  <p>Based on <a href="http://arma.sourceforge.net/docs.html#submat" rel="nofollow noreferrer">this documentation</a>, contiguous indices such as [0, 1, 2, ..., m-1] can be extracted easily using <code>X.cols(0, m - 1)</code> if m &lt;= p. However, I couldn't find a good way to subset a matrix with the index vector <code>IDX</code> described above.</p>
  
  <p>I wonder how I complete this code to give a desired output. </p>
  
  <p>My "subset_armamat.cpp" file looks like</p>
  
  <pre><code>// [[Rcpp::depends(RcppArmadillo)]]
  #include &lt;RcppArmadillo.h&gt;
  using namespace Rcpp;
  using namespace arma;
  
  // [[Rcpp::export]]
  mat subset_armamat(mat X, int k){
    uvec IDX = "every k-th integer from 0 to X.ncols";
    return X.cols(IDX);
  }
  </code></pre>
  
  <p>and R code to execute the defined function is </p>
  
  <pre><code>library("Rcpp")
  sourceCpp("subset_armamat.cpp")
  subset_armamat(matrix(1:10, 2, 5, byrow = T), 2)
  </code></pre>
  
  <p>This is expected to produce a 2-by-3 matrix as the following R code would give</p>
  
  <pre><code>&gt; matrix(1:10, 2, 5, byrow = T)[,seq(1, 5, by = 2)]
       [,1] [,2] [,3]
  [1,]    1    3    5
  [2,]    6    8   10
  </code></pre>
  
  <p>It would be very appreciated if you give any input. </p>
  
  <p>p.s. I've tried to </p>
  
  <ul>
  <li>generate a sequence vector <code>seq(1,m) * 2</code> manually, but this does not work with <code>X.cols()</code>. </li>
  <li>or find an index using <code>find(seq(1,p) % 2 == 0)</code>, but <code>%</code> operator does not work well between <code>seq(1,p)</code> and <code>2</code>. </li>
  </ul>