<div dir="ltr">Another way of doing what Cedric did, if you're willing to overwrite the original vars:<div><br></div><div>test[varA > varB, `:=`(VarA = VarB, VarB = VarA)]</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 16, 2016 at 9:36 AM, Cedric Duprez <span dir="ltr"><<a href="mailto:Cedric.Duprez@ign.fr" target="_blank">Cedric.Duprez@ign.fr</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>
Perhaps something like this :<br>
<br>
> test <- data.table(varA=c("a", "a", "a", "b", "b", "b", "c", "c",<br>
"c"), varB=c("a", "b", "c", "a", "b", "c", "a", "b", "c"))<br>
> test<br>
varA varB<br>
1: a a<br>
2: a b<br>
3: a c<br>
4: b a<br>
5: b b<br>
6: b c<br>
7: c a<br>
8: c b<br>
9: c c<br>
> test[, `:=`(varA2 = pmin(varA, varB), varB2 = pmax(varA, varB))]<br>
> test<br>
varA varB varA2 varB2<br>
1: a a a a<br>
2: a b a b<br>
3: a c a c<br>
4: b a a b<br>
5: b b b b<br>
6: b c b c<br>
7: c a a c<br>
8: c b b c<br>
9: c c c c<br>
<br>
The two new variables (varA2 and varB2) look like what you're waiting<br>
for. Isn't it?<br>
<br>
Regards,<br>
Cedric<br>
<div class="HOEnZb"><div class="h5">_______________________________________________<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" rel="noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br>
</div></div></blockquote></div><br></div>