I have a dataframe with 2 columns - id and term - and I am trying to make all possible combinations of term according to the id. Here's an example:
df <- dataframe (id = c(1,1,1,1,2,2,3), term = c(aaa, aab, aac, aad, aba, abb, aaa))
This is the result I would like to obtain:
- 1 aaa aab
- 1 aaa aac
- 1 aaa aad
- 1 aab aac
- 1 aab aad
- 1 aac aad
- 2 aba abb
I tried crating two equal datasets a and b, and combining them with this code
a <- df
b <- df
for (p in a) {
for (q in b) {
if (b$id == a$id)
rez <- rbin(crossing(a$term, b$term))
}
}
but the result is just all possible combinations of term.
Any suggestions how to solve this? Thanks!