V <- c(1,3,2,4,2,3,1);
X <- 3;
pos <-V[V == X];
pos
is 3 3
.
what I need is the positions of all 3;
I need 2
and 6
; which are the positions of 3
in V
.
Use which
pos <- which(V == 3)
Not what you're asking for, but useful anyway: you can also use which.min
and which.max
to find the position of the minimum and maximum value of the array.
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