I have a dtm and want to extract the top 5 terms by frequency for each document from the document term matrix.
I have a dtm built using the tm package
Terms
Docs aaaa aac abrt abused accept accepted
1 0 0 0 0 0 0
2 0 0 0 0 0 0
3 0 0 0 0 0 0
4 0 0 0 0 0 0
5 0 0 0 0 0 0
6 0 0 0 0 0 0
required output should be of the form:
Id
1 Term1 Term2 Term3 Term4 Term5
2 Term1 Term2 Term3 Term4 Term5
and so on for all the documents.
I have tried all the solutions available from stackoverflow ans other sources like Make dataframe of top N frequent terms for multiple corpora using tm package in R (converted to tdm and tried to bring to the output form but did not work)and others but noting seem to work.