[Rcpp-devel] Mimicing of X[ X[,col]==val, ] with RcppArmadillo

c s conradsand.arma at gmail.com
Fri Jun 1 05:04:44 CEST 2012


On Thu, May 31, 2012 at 11:07 PM, Søren Højsgaard <sorenh at math.aau.dk> wrote:
> I would expect that there is a way of doing this without having
> to jump "into" armadillo "back" to Rcpp and "into" Armadillo again.
> I just can't spot an easier way. If a simpler solution exists I would
> be interested to know...

Perhaps Armadillo's find() in conjunction with .elem() can help:

http://arma.sourceforge.net/docs.html#find
http://arma.sourceforge.net/docs.html#submat

For example, set any element of X greater than 0.5 to 123:

mat X = randu<mat>(5,5);
X.elem( find(X > 0.5) ).fill(123.0);


More information about the Rcpp-devel mailing list