I have the following R code:
CutMatrix <- FullMatrix[, colSums( FullMatrix[-1,] != FullMatrix[-nrow( FullMatrix ), ] ) > 0]
Which takes a matrix - FullMatrix and makes a CutMatrix by finding which columns in the FullMatrix have columns with more than 1 unique value - so all columns with the same value are eliminated. I'm wondering if I can use Rcpp to speed this up for large matrices, but I'm unsure of the best way to do this - whether there is a sugarish way to easily do this (say by looping through the cols and counting the number of unique values) or if I would have to use something more complicated from the STL.
I thought maybe something like the following was a start (I haven't managed to get all the way) - trying to do the operation in between the colSums braces in the R function, but I don't think I'm sub-setting the matrix correctly since it doesen't work.
src <- '
//Convert the inputted character matrix of DNA sequences an Rcpp class.
Rcpp::CharacterMatrix mymatrix(inmatrix);
//Get the number of columns and rows in the matrix
int ncolumns = mymatrix.ncol();
int numrows = mymatrix.nrow();
//Get the dimension names
Rcpp::List dimnames = mymatrix.attr("dimnames");
Rcpp::CharacterMatrix vec1 = mymatrix(Range(1,numrows),_);
Rcpp::CharacterMatrix vec2 = mymatrix(Range(0,numrows-1),_);
'
uniqueMatrix <- cxxfunction(signature(inmatrix="character"), src, plugin="Rcpp")
Thanks, Ben.