I have a list of words, each word appears in a text (there are 5 texts) and has a frequency in each text. I want an output which can group the word and the text(s) that it appears and the frequency score(s). For example:
df <- data.frame(word=c("a", "b", "c", "e", "g", "a", "c", "f", "b", "d", "e", "c", "a", "h", "i"),text=c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5), freq=c(10,3,5,8,2,6,7,4,9,11,18,2,1,5,6))
> print(df)
word text freq
1 a 1 10
2 b 1 3
3 c 1 5
4 e 2 8
5 g 2 2
6 a 2 6
7 c 3 7
8 f 3 4
9 b 3 9
10 d 4 11
11 e 4 18
12 c 4 2
13 a 5 1
14 h 5 5
15 i 5 6
I want to have an output that shows , for example, word "a" appearing in text 1, 2, and 5 with the frequency being 10, 6, and 1 respectively. Similarly to all the other words in the list.