我正在使用tm包來計算數據集的term-document-matrix,我現在必須將文檔 - 矩陣文字寫入文件,但是當我在R中使用寫入函數時,出現錯誤。寫一個簡單的三元組矩陣到文件?
這裏是我使用的代碼,我得到的錯誤:
data("crude")
tdm <- TermDocumentMatrix(crude, control = list(weighting = weightTfIdf, stopwords = TRUE))
dtm <- DocumentTermMatrix(crude, control = list(weighting = weightTfIdf, stopwords = TRUE))
,這是錯誤,而我用的是write.table命令對這個數據:
Error in cat(list(...), file, sep, fill, labels, append) : argument 1 (type 'list') cannot be handled by 'cat'
我明白tbm是Simple Triplet Matrix類型的對象,但我怎樣才能將它寫入一個簡單的文本文件。
謝謝Tony和Shane!解決方案幫助我度過了美好的時光 – 2010-07-16 04:25:48
我不認爲這個工作了,'不能強制類......到data.frame' – wordsforthewise 2018-01-28 07:12:11
@wordsforthewise在Windows 7,R版本3.4.3和tm_0.7-3下適用於我的工作 – 2018-02-01 18:50:03