I have a dataframe like below:
data.frame(id = rep(1:2, each=4),
word = c('apple', 'pear', 'orange', 'banana',
'apple', 'watermellon','orange', 'grape') )
I need to convert the data to the form below. Need to pair up all words in the word column within each group (id) and create two columns word1
and word2
.
id word1 word2
1 apple pear
1 apple orange
1 apple banana
1 pear orange
1 pear banana
1 orange banana
2 apple watermellon
2 apple Orange