开发者

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

开发者 https://www.devze.com 2023-03-12 13:58 出处:网络
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;
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

精彩评论

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