我有一个由年份命名的 39 个文本文件的语料库 - 1945.txt、1978.txt.... 2013.txt。
我已将它们导入 R 并使用 TM 包创建了一个文档术语矩阵。我正在尝试调查从 1945 年到 2013 年,与 term'fraud' 相关的单词多年来的变化情况。所需的输出将是一个 39 x 10/5 的矩阵,其中年份作为行标题,前 10 或 5 个术语作为列。
任何帮助将不胜感激。
提前致谢。
我的 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 .............
.
.
.
.
.
.