<a href="http://en.wiktionary.org/wiki/oy_gevalt">Oy gevalt</a>!.Am I correct to believe that the technique is rearranging the data.table so that J can accept the input as pertaining to a secondary key? That seems as if it is too much work for me and my computer. I will rather stick to the vector scan methods for now.<div>
<br></div><div><br clear="all">Farrel<br><br>
<br><br><div class="gmail_quote">On Thu, Jan 19, 2012 at 00:23, Steve Lianoglou <span dir="ltr"><<a href="mailto:mailinglist.honeypot@gmail.com">mailinglist.honeypot@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
Just to redo the example Matthew is pointing to, I'll put it here.<br>
<br>
Note that the current answer is that there is no "neat" way to do it<br>
just, and it takes some intermediary steps for you to get what you<br>
want. Here this amounts to creating the `idx` table w/ the keys<br>
swapped and an `i` column.<br>
<br>
There is a feature request to make it neater:<br>
<a href="https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1007&group_id=240&atid=978" target="_blank">https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1007&group_id=240&atid=978</a><br>
<br>
here's an example:<br>
<br>
R> dt <- data.table(a=c('a','a','a','a','b','b','b','b'),<br>
b=c('a','b','a','b','a','b','b','a'),c=1:8,key=c('a','b'))<br>
R> dt<br>
a b c<br>
[1,] a a 1<br>
[2,] a a 3<br>
[3,] a b 2<br>
[4,] a b 4<br>
[5,] b a 5<br>
[6,] b a 8<br>
[7,] b b 6<br>
[8,] b b 7<br>
<br>
R> idx <- dt[,list(b, a, i=1:nrow(dt))]<br>
R> key(idx) <- c('b','a')<br>
<br>
Now let's grab all rows from `dt` where the secondary key == 'b'<br>
<br>
R> dt[ idx[J("b"), i]$i ]<br>
a b c<br>
[1,] a b 2<br>
[2,] a b 4<br>
[3,] b b 6<br>
[4,] b b 7<br>
<br>
HTH,<br>
-steve<br>
<div class="HOEnZb"><div class="h5"><br>
On Wed, Jan 18, 2012 at 11:42 PM, Matthew Dowle <<a href="mailto:mdowle@mdowle.plus.com">mdowle@mdowle.plus.com</a>> wrote:<br>
> I find Nabble is better for searching the archive. It seems to be<br>
> optimised for discussion list search. Link on homepage, 'secondary' into<br>
> search box, and e.g. thread " Select from second key but not first".<br>
><br>
>> Dear Matthew<br>
>><br>
>> Thank you for trying to guide me. Unfortunately I was not able to really<br>
>> comprehend what I was reading<br>
>><br>
>> I entered the following into google search "site:<br>
>> <a href="http://lists.r-forge.r-project.org/pipermail/datatable-help/" target="_blank">lists.r-forge.r-project.org/pipermail/datatable-help/</a> secondary"<br>
>><br>
>> I got many hits and I could see a discussion but could not fathom how it<br>
>> related to my question.<br>
>><br>
>><br>
>> Would love some help from you or someone else. I want to be able to select<br>
>> by a criterion in the second key and accept all possible values in the<br>
>> first key.<br>
>> Farrel Buchinsky<br>
>> Google Voice Tel: <a href="tel:%28412%29%20567-7870" value="+14125677870">(412) 567-7870</a><br>
>><br>
>><br>
>><br>
>> On Wed, Jan 18, 2012 at 22:40, Matthew Dowle <<a href="mailto:mdowle@mdowle.plus.com">mdowle@mdowle.plus.com</a>><br>
>> wrote:<br>
>><br>
>>> Hi. Try searching datatable-help for 'secondary'.<br>
>>><br>
>>> > In setkey it is possible to have multiple columns be a key. There is<br>
>>> > however an order to it. To select all the rows by a particular value<br>
>>> in<br>
>>> > the<br>
>>> > first key is easy<br>
>>> > DT[J("a value from the first key")]<br>
>>> ><br>
>>> > It is even quite easy to select by an AND criteria that incorporates<br>
>>> the<br>
>>> > second key<br>
>>> > DT[J("a value from the first key","a value from the second key")]<br>
>>> ><br>
>>> > But what happens if one wanted to select by only one criteria being a<br>
>>> a<br>
>>> > value that must be present in the second key? I was hoping to get<br>
>>> lucky<br>
>>> by<br>
>>> > just leaving it blank. But it did not see to work.<br>
>>> ><br>
>>> > DT[J(,"a value from the second key")]<br>
>>> ><br>
>>> > I would love to know what you do.<br>
>>> ><br>
>>> ><br>
>>> > Farrel<br>
>>> > _______________________________________________<br>
>>> > datatable-help mailing list<br>
>>> > <a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
>>> ><br>
>>> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br>
>>><br>
>>><br>
>>><br>
>>><br>
>>><br>
>><br>
><br>
><br>
><br>
><br>
><br>
><br>
> _______________________________________________<br>
> datatable-help mailing list<br>
> <a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br>
<br>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Steve Lianoglou<br>
Graduate Student: Computational Systems Biology<br>
| Memorial Sloan-Kettering Cancer Center<br>
| Weill Medical College of Cornell University<br>
Contact Info: <a href="http://cbio.mskcc.org/~lianos/contact" target="_blank">http://cbio.mskcc.org/~lianos/contact</a><br>
</font></span></blockquote></div><br></div>