[R] simple loop questions

From: <xueke_at_pdx.edu>
Date: Sat, 23 Apr 2011 03:31:48 -0700

Hi all,

I am trying to write a loop to return the matched index for a column of values. Here is an simple example of this,

0 5
1 2
2 2
3 4
4 1
5 4
6 2

In this case, A is an index column for B. Now I have this new column C with just two values of 2 and 4. I want to match column C with column B, and return the matched indexes. So what I desire is to return:

[1] 1 2 6
[2] 3 5

Since value 2 corresponds to indexes 1,2,6, and 4 corresponds to indexes 3,5.

Is there any way to write a loop to have this done? Thank you for the help.


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 Sat 23 Apr 2011 - 12:39:43 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 Sat 23 Apr 2011 - 13:50:32 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