@nirgrahamuk df_1 and df_2 directly taken from my original post
df_1 <- structure(list(query = structure(c(3L, 4L, 5L, 6L, 7L, 1L, 9L,
10L, 2L, 8L, 3L, 4L, 5L, 8L, 6L, 6L, 8L, 7L), .Label = c("(+)-1(10),4-Cadinadiene",
"(2E,7R,11R)-2-Phyten-1-ol", "A1", "A2", "A3", "A4", "A5", "Falcarinone",
"Leucodelphinidin", "Lignin"), class = "factor"), target = structure(c(5L,
7L, 3L, 7L, 6L, 9L, 1L, 2L, 10L, 11L, 1L, 11L, 2L, 8L, 10L, 10L,
4L, 9L), .Label = c("(+)-1(10),4-Cadinadiene", "(2E,7R,11R)-2-Phyten-1-ol",
"A1", "A100", "A2", "A3", "A5", "A6", "Falcarinone", "Leucodelphinidin",
"Lignin"), class = "factor"), weight = c(0.6, 0.5, 0.75, 0.88,
0.99, 0.09, 0.876, 0.778, 0.55, 1, 1, 1, 1, 1, 1, 1, 1, 1)), class = "data.frame", row.names = c(NA,
-18L))
df_2 <- structure(list(query = structure(c(2L, 4L, 2L, 6L, 5L, 1L, 8L,
9L, 3L, 4L, 5L, 7L, 6L), .Label = c("(+)-1(10),4-Cadinadiene",
"A1", "A11", "A2", "A3", "A4", "Falcarinone", "Leucodelphinidin",
"Lignin-2"), class = "factor"), target = structure(c(5L, 7L,
6L, 7L, 7L, 9L, 2L, 4L, 1L, 11L, 3L, 8L, 10L), .Label = c("(+)-1(10),4-Cadinadiene",
"(+)-1(10),4-Cadinadiene-100", "(2E,7R,11R)-2-Phyten-1-0l", "(2E,7R,11R)-2-Phyten-1-ol",
"A2", "A3", "A5", "A6", "Falcarinone", "Leucodelphinidin", "Lignin"
), class = "factor")), class = "data.frame", row.names = c(NA,
-13L))
After running setDT(df_1)[,c("query", "target") := list(pmin(query,target), pmax(query,target))] getting this type of table.
df_1 <- structure(list(query = structure(c(3L, 4L, 5L, 6L, 7L, 1L, 9L,
10L, 2L, 8L, 3L, 4L, 5L, 8L, 6L, 6L, 8L, 7L), .Label = c("(+)-1(10),4-Cadinadiene",
"(2E,7R,11R)-2-Phyten-1-ol", "A1", "A2", "A3", "A4", "A5", "Falcarinone",
"Leucodelphinidin", "Lignin"), class = "factor"), target = structure(c(3L,
4L, 5L, 6L, 7L, 1L, 9L, 10L, 2L, 8L, 3L, 4L, 5L, 8L, 6L, 6L,
8L, 7L), .Label = c("(+)-1(10),4-Cadinadiene", "(2E,7R,11R)-2-Phyten-1-ol",
"A1", "A2", "A3", "A4", "A5", "Falcarinone", "Leucodelphinidin",
"Lignin"), class = "factor"), weight = c(0.6, 0.5, 0.75, 0.88,
0.99, 0.09, 0.876, 0.778, 0.55, 1, 1, 1, 1, 1, 1, 1, 1, 1)), class = c("data.table",
"data.frame"), row.names = c(NA, -18L), .internal.selfref = <pointer: 0x560ad10aa500>)