[R] Extract indices after comparing two vectors

From: Chee Chen <chee.chen_at_yahoo.com>
Date: Mon, 18 Apr 2011 19:40:45 -0400


Dear All,
I would like to ask a question about how to locate the indices after comparing two numeric vectors. Say, I have, A <- c(1,2,3,4) and A <- c(0,3,1,5) and we cmpare:
> idx <- A<B

So:
> idx

[1] FALSE TRUE FALSE TRUE Question 1:
I would like to get a vector that stores the indices for entries of A such that this relationship is true. In this case, a vector idx1 < c(2,4), because the 2nd and 4th entries of A satisfy the conditions

Question 2:
I would like to know the maximum index of the entry in A for which the relationship is true. In this case, max_indx = 4, since the 4th entry of A is such.

Could you please give me some hints?

Thank you,
-Chee

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 18 Apr 2011 - 23:48:00 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Apr 2011 - 00:00:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive