2015-03-31 69 views
0

我有一個名爲train_dtm的DocumentTermMatrix,我想規範所有文檔中術語頻率的頻率計數。我現在面臨的問題是所產生的基質也應該是類型DocumentTermMatrix的,因爲我想歸一化矩陣傳遞給TopicModels包的另一種方法LDA在R.您如何規範化R中文檔術語矩陣的行?

下面是我使用的方法:

docs_dtm <- DocumentTermMatrix(docs) 

現在,我希望上面的documenttermmatrix的行被規範化。我甚至嘗試添加的控制參數通過

docs_dtm <- DocumentTermMatrix(docs, control=list(weighting = function(x) weightTf(x, normalize=TRUE))) 

,但上面的調用拋出一個錯誤說

Error in weightTf(x, normalize=TRUE): unused argument (normalize = TRUE) 

我已經寫了使用apply()方法標準化train_dtm的值的方法,但它不返回一個DocumentTermMatrix類型的矩陣。

是否有另一種方法來完成上述任務?

+0

你有一個最小的工作的例子嗎? – 2015-03-31 14:40:52

+0

感謝您的回覆。上面粘貼了我的代碼。 – 2015-03-31 14:44:27

回答

0

你能嘗試直接傳遞權重參數,例如:

docs_dtm <- DocumentTermMatrix(docs, control = list(weighting = weightTf, normalize = TRUE))