我有一个cluto格式的文档术语矩阵:
#Document #Term #TotalItem
term-x weight-x term-y weight-y (for only nonzeros terms, a row per document)
我想从这个文件创建DocumentTermMatrix(tm包)而不是语料库,这可能吗?
Cluto File:
2 3 3
1 3 3 4
2 8
Row File:
car
plane
Column File:
x
y
z
解决方案:
dtm = as.DocumentTermMatrix(read_stm_CLUTO(file), weightTf);
rows <- scan("rows.txt", what="", sep="\n");
columns <- scan("columns.txt", what="", sep="\n");
dtm$dimnames = list(rows,columns);
答案 0 :(得分:1)
这应该这样做:
require(slam)
as.DocumentTermMatrix(read_stm_CLUTO(file), weightTf)
如果您可以链接到您的CLUTO文件或在Q中添加它的摘录,我们可以查看行名和列名。