I have a corpus of 39 text files named by the year - 1945.txt, 1978.txt.... 2013.txt.
I've imported them into R and created a Document Term Matrix using TM package. I'm trying to investigate how words associated with term'fraud' have changed over years from 1945 to 2013. The desired output would be a 39 by 10/5 matrix with years as row titles and top 10 or 5 terms as columns.
Any help would be greatly appreciated.
Thanks in advance.
Structure of my TDM:
> str(ytdm)
List of 6
$ i : int [1:6791] 5 7 8 17 32 41 42 55 58 71 ...
$ j : int [1:6791] 1 1 1 1 1 1 1 1 1 1 ...
$ v : num [1:6791] 2 4 2 2 2 8 4 3 2 2 ...
$ nrow : int 193
$ ncol : int 39
$ dimnames:List of 2
..$ Terms: chr [1:193] "abus" "access" "account" "accur" ...
..$ Docs : chr [1:39] "1947" "1976" "1977" "1978" ...
- attr(*, "class")= chr [1:2] "TermDocumentMatrix" "simple_triplet_matrix"
- attr(*, "Weighting")= chr [1:2] "term frequency" "tf"
My ideal output is like this:
1947 account accur gao medicine fed ......
1948 access .............
.
.
.
.
.
.