I'm re-writing an R program in c++. I'm wondering if there's a c++ equivalent or way of achieving the same result as the which() function in R. Here's what the which() function effectively accomplishes:
# A sequence
x <- c(10, 20, 30, 40, 50)
# This should return a numerical index (1, 2) since only the first two elements are <= 20
which(x <= 20)
So which() essentially tests the expression and returns the TRUE indices of the logical object. I tried searching for an Rcpp sugar but can't seem to find one. There's which_max() and which_min(), which return the numerical indices for the max and min elements, respectively. I could always use the R function in Rcpp, but I'm interested in learning the c++ way if possible.