I am not sure how to solve this problem. My dataframe looks like this (but a lot bigger):
df <- data.frame(word = c('word1','word2', 'word3', 'word4', 'word5', 'word6', 'word7'), code = c(1 , 2, 2, 2, 1, 1, 2), modality = c('cog', 'emo', 'soc', 'cog_emo', 'soc', 'soc_emo_cog', 'emo'))
df
word code modality
1 word1 1 cog
2 word2 2 emo
3 word3 2 soc
4 word4 2 cog_emo
5 word5 1 soc
6 word6 1 soc_emo_cog
7 word7 2 emo
The modality column shows which modality the word is assigned to. But I need to count the number of words assigned to one modality. If one word is assigned to multiple modalities it has to be counted for each of them. Therefore I would want to duplicate the whole row in which multiple modalities are assigned so that I have one modality per row. Somewhat like this:
word code modality
1 word1 1 cog
2 word2 2 emo
3 word3 2 soc
4 word4 2 cog
5 word4 2 emo
6 word5 1 soc
7 word6 1 soc
8 word6 1 emo
9 word6 1 cog
10 word7 2 emo
As I said the data frame is a lot bigger, so I cannot do it manually. Thank you!!