For NumericVector, I can subset a smaller NumericVector by using an IntegerVector that contains the positions to subset.
e.g. suppose x<-c(1,2,2,3,4,5), idx<-c(1,3,4), and xsub<-x[idx] which is 1 2 3.
Within RCpp, I can simply use xsub=x[idx].
Is there a similar way to subset the rows of a NumericMatrix using the IntegerVector?
For example, the following code xmatsub=xmat(idx,_) didn't work for me.
There isn't a way. You have to do it manually, which is not that complicated.
NumericMatrix res( idx.size(), m.rows() ) ;
for( int i=0; i<idx.size(); i++){
res.row(i) = m.row(idx[i]-1) ;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With