I want to extract all pairs within groups of a data.table by two columns.
I have the following code:
dt = data.table(g1 = c(1, 1, 1, 2, 2, 2, 2),
g2 = c(3, 3, 4, 5, 5, 6, 6),
values = letters[1:7])
dt[, .(ind = combn(values, 2, paste0, collapse = "")), by = .(g1, g2)]
But this returns the error
Error in combn(values, 2, paste0, collapse = "") : n < m
The ideal result is some object that contains groups such as:
a,b
c
d,f
g,h
If c was not included because there is only one value, that is not a huge concern to me.
Is this possible to get using data.table?
Thanks in advance.