开发者

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

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜