Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get all the numbers greater than x with positions?

Tags:

r

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.

like image 688
Robin Avatar asked Jun 12 '11 13:06

Robin


1 Answers

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.

like image 55
nico Avatar answered Sep 20 '22 03:09

nico