Hi, I have a string vector, say, x <- "a", "aab" and anther string vector, say, y <- "a", "aa", "aab", "aabc". Is there any R function to get the indices of y for the elements of x, that is, foo(x, y) will give me the index vector c(1, 3)? I know i can combine apply() and grep("^aab$", y) to do it. But is there any elegant R function I can use? Thanks, -Luke [[alternative HTML version deleted]]
On Sun, Apr 16, 2006 at 12:26:29AM -0400, Luke wrote:> > x <- "a", "aab" > y <- "a", "aa", "aab", "aabc". > > Is there any R function to get the indices of y for the elements of x, that > is, foo(x, y) will give me the index vector c(1, 3)?match(x, y) cu Philipp -- Dr. Philipp Pagel Tel. +49-8161-71 2131 Dept. of Genome Oriented Bioinformatics Fax. +49-8161-71 2186 Technical University of Munich Science Center Weihenstephan 85350 Freising, Germany and Institute for Bioinformatics / MIPS Tel. +49-89-3187 3675 GSF - National Research Center Fax. +49-89-3187 3585 for Environment and Health Ingolst?dter Landstrasse 1 85764 Neuherberg, Germany http://mips.gsf.de/staff/pagel