Another way of doing what Cedric did, if you're willing to overwrite the original vars:
test[varA > varB, `:=`(VarA = VarB, VarB = VarA)] On Thu, Jun 16, 2016 at 9:36 AM, Cedric Duprez <[email protected]> wrote: > Hi, > > Perhaps something like this : > > > test <- data.table(varA=c("a", "a", "a", "b", "b", "b", "c", "c", > "c"), varB=c("a", "b", "c", "a", "b", "c", "a", "b", "c")) > > test > varA varB > 1: a a > 2: a b > 3: a c > 4: b a > 5: b b > 6: b c > 7: c a > 8: c b > 9: c c > > test[, `:=`(varA2 = pmin(varA, varB), varB2 = pmax(varA, varB))] > > test > varA varB varA2 varB2 > 1: a a a a > 2: a b a b > 3: a c a c > 4: b a a b > 5: b b b b > 6: b c b c > 7: c a a c > 8: c b b c > 9: c c c c > > The two new variables (varA2 and varB2) look like what you're waiting > for. Isn't it? > > Regards, > Cedric > _______________________________________________ > datatable-help mailing list > [email protected] > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help >
_______________________________________________ datatable-help mailing list [email protected] https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
