[Rcpp-devel] Non-contiguous submatrix

Dirk Eddelbuettel edd at debian.org
Mon Aug 26 13:24:42 CEST 2013


On 26 August 2013 at 12:19, Simon Zehnder wrote:
| Dear Rcpp::Users and Rcpp::Devels,
| 
| I am right now working on a relabeling algorithm where I have a function
| taking a permutation matrix of all permutations of the labels. Inside the
| function the values should be permuted in respect to a row of this
| matrix. In R I would use the following commands:
| 
| values <- matrix(rnorm(4), ncol = 2, nrow = 2, byrow = TRUE)
| perm <- as.matrix(expand.grid(seq(1, 2), seq(1, 2)))
| index <- perm[which(perm[, 1] != perm[, 2]),]
| values[, index[, 1]]
| values[, index[, 2]]
| 
| I found this thread on stackoverflow:
| http://stackoverflow.com/questions/8435169/selecting-a-non-contiguous-submatrix-in-rcpp. Are
| there any proceedings for non-contiguous submatrices in Rcpp?

Not in Rcpp -- but Armadillo has it and this example on the Rcpp Gallery uses
it along with RcppArmadillo:

  http://gallery.rcpp.org/articles/armadillo-subsetting/

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list