[Rcpp-devel] Question on syntactic sugar

Gregor Kastner mailinglist at gmx.at
Thu Jan 5 07:41:36 CET 2012


Dear all,

I have a (small) vector "r" containing values and a (large) vector
"index" containing indices. Is there an easy way to select the elements of
"r" that are indexed by "index"?

I.e., is there a way to reproduce the following R code with Rcpp (without
using loops)?

r <- c(1,11,111)
index <- c(2,2,1)
r[index]

Thanks in advance,
/g


More information about the Rcpp-devel mailing list