[R] Fast way to finding index in Vector

jim holtman jholtman at gmail.com
Tue Jan 13 04:14:29 CET 2009


Is this what you want:

> repo <- c("AAA", "AAT", "AAC", "AAG", "ATA","ATT")
> qr <- c("AAC", "ATT", "ATT","AAC", "ATT", "ATT", "AAT", "ATT", "ATT")
> match(qr, repo)
[1] 3 6 6 3 6 6 2 6 6
>



On Mon, Jan 12, 2009 at 9:22 PM, Gundala Viswanath <gundalav at gmail.com> wrote:
> Hi Jorge and all,
>
> How can I modified your code when
>
> query size can be bigger than repository,
> meaning that it can contain repeats.
>
> e.g. qr <- c("AAC", "ATT", "ATT","AAC", "ATT", "ATT", "AAT", "ATT", "ATT",  )
>
>
> Sorry, I should have mentioned this earlier.
>
>
> - Gundala Viswanath
> Jakarta - Indonesia
>
>
>
> On Tue, Jan 13, 2009 at 11:11 AM, Jorge Ivan Velez
> <jorgeivanvelez at gmail.com> wrote:
>>
>> Perhaps
>> which(repo%in%qr)
>> ?
>> HTH,
>>
>> Jorge
>>
>>
>> On Mon, Jan 12, 2009 at 9:07 PM, Gundala Viswanath <gundalav at gmail.com>
>> wrote:
>>>
>>> Dear all,
>>>
>>> Suppose I have the following vector as repository:
>>>
>>> > repo <- c("AAA", "AAT", "AAC", "AAG", "ATA","ATT")
>>>
>>> Given another query vector
>>>
>>> > qr <- c("AAC", "ATT")
>>>
>>> is there a way I can find the query index in repository in a fast way.
>>>
>>> Giving:
>>>
>>> [1] 3 6
>>>
>>> Typically the size of  repo is around ~12million element, and
>>> query around ~1 million element.
>>>
>>>
>>> - Gundala Viswanath
>>> Jakarta - Indonesia
>>>
>>> ______________________________________________
>>> 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.
>>
>>
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list