Dear njhuang86, Here is one way: x <- c('a', 't', 'c', 'y', 'g') y <- c('a', 'a', 'g', 's') table(factor(y, levels = x)) # a t c y g # 2 0 0 0 1
HTH, Jorge On Tue, Jul 7, 2009 at 3:28 PM, njhuang86 <njhuan...@yahoo.com> wrote: > > Hi all, > Suppose I have x = c('a', 't', 'c', 'y', 'g') > and also y = c('a', 'a', 'g', 's') > > If I do something like x%in%y, I obtain a vector like this: [TRUE, FALSE, > FALSE, FALSE, TRUE] which I can easily turn into this: [1, 0, 0, 0, 1]. > I was wondering is there anyway for me to get a vector back in return in > the > form of: [2, 0, 0, 0, 1]? Essentially, the 2 will tell me that in the first > position of vector 'x', there were two matches found with vector y. > > Thanks a ton in advance! > -- > View this message in context: > http://www.nabble.com/find-duplicates...-need-help%21-tp24379828p24379828.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. > [[alternative HTML version deleted]] ______________________________________________ R-help@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.