<div dir="ltr">Thanks, Steve. I was thinking that that approach spends too much memory or computational time by making a copy (while I was thinking of editing dt1 in-place). If I'm wrong, maybe that's what I ought to do. If not, I look forward to hearing your other thoughts.<div>
--Frank</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 15, 2013 at 11:23 AM, Steve Lianoglou <span dir="ltr"><<a href="mailto:lianoglou.steve@gene.com" target="_blank">lianoglou.steve@gene.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Frank,<br>
<br>
I don't have time to get into the details of your entire question<br>
right now, but:<br>
<div class="im"><br>
On Thu, Aug 15, 2013 at 8:49 AM, Frank Erickson <<a href="mailto:FErickson@psu.edu">FErickson@psu.edu</a>> wrote:<br>
> Hi,<br>
><br>
> I really like the DT1[DT2,z:=...] idiom. Unfortunately, the value of a<br>
> merge() on other columns is a new data.table, so modifying DT1, like<br>
> merge(DT1,DT2,by=...)[,z:=...], is not possible. Or is there actually a way<br>
> to do this that I am missing?<br>
<br>
</div>I just wanted to mention that unless I am misunderstanding what you<br>
want, this is entirely possible, and the way you suggest it might work<br>
is actually the way to do it.<br>
<br>
Consider:<br>
<br>
R> dt1 <- data.table(a=sample(letters[1:2], 5, rep=T), b=runif(5), key='a')<br>
R> dt2 <- data.table(a=c('a', 'b'), c=rnorm(5), key='a')<br>
<br>
R> dt1<br>
a b<br>
1: a 0.02517147<br>
2: a 0.85459776<br>
3: a 0.67472168<br>
4: a 0.89684769<br>
5: b 0.11619613<br>
<br>
R> dt2<br>
a c<br>
1: a -0.07817539<br>
2: b -1.28897689<br>
<br>
R> out <- merge(dt1, dt2)[, d := b + c]<br>
a b c d<br>
1: a 0.02517147 -0.07817539 -0.05300392<br>
2: a 0.85459776 -0.07817539 0.77642237<br>
3: a 0.67472168 -0.07817539 0.59654629<br>
4: a 0.89684769 -0.07817539 0.81867230<br>
5: b 0.11619613 -1.28897689 -1.17278075<br>
<br>
Will come back later to look through the rest of your question if<br>
still necessary.<br>
<br>
HTH,<br>
-steve<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Steve Lianoglou<br>
Computational Biologist<br>
Bioinformatics and Computational Biology<br>
Genentech<br>
</font></span></blockquote></div><br></div>