Let me explain what the 'which' function does:
From GNU-R help:
which indices are TRUE?
Give the ‘TRUE’ indices of a logical object, allowing for array indices.
or showing some code: (GNU-R starts counting indices with 1)
> x <- c(1,2,3,1,3,5);
> which(x == 1);
[1] 1 4
> which(x == 3);
[1] 3 5
> ll <- c(TRUE,FALSE,TRUE,NA,FALSE,FALSE,TRUE);
> which(ll);
[1] 1 3 7
Does anyone know a similar function in C/C++?
Thanks for your help
rinni
You have to understand that R is vectorised, whereas C first and foremost works on individual atomistic data pieces: a single int
, double
, ...
With C++, you can look into STL algorithms with which you approach this.
Lastly, at the R and C++ intersection, our Rcpp package has some vectorized operations in C++ which mimic some operations; see the Rcpp-sugar pdf vignette for more (and/or some of our talks on Rcpp).
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