Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

Find index of all max/min values in vector in Rcpp

$
0
0

Let's say I have a vector

v = c(1,2,3)

I can easily find which element is the max using

cppFunction('int which_maxCpp(NumericVector v) {
  int z = which_max(v);
  return z;
}')

which_maxCpp(v)

2

However, if I have a vector such as

v2 = c(1,2,3,1,2,3)

I also get

which_maxCpp(v2)

2

is there a way to get which_max (or which_min) to find the index of all min/max elements of a vector, or is another (I'd assume native C++) function needed?


Viewing all articles
Browse latest Browse all 201894

Trending Articles