R CLUTO文件术语矩阵到tm文件术语矩阵
我有一个cluto格式的文档术语矩阵:R CLUTO文件术语矩阵到tm文件术语矩阵,r,text-mining,tm,cluto,R,Text Mining,Tm,Cluto,我有一个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 解决方案
#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);
dtm=as.DocumentTermMatrix(读取(文件),权重tf);
行这应该可以做到:
require(slam)
as.DocumentTermMatrix(read_stm_CLUTO(file), weightTf)
如果你可以链接到你的CLUTO文件或者在你的Q中添加一个摘录,我们可以查看行和列名
帽子提示:这个怎么样<代码>要求(slam);as.DocumentTermMatrix(read_stm_CLUTO(file),weightTf)
@Ben Perfect,你能把它作为一个答案键入,这样我就可以接受了。有没有办法传递行名和列名?看起来您已经对列/列名进行了排序。您可以执行dtm$dimnames=list(文档=行,术语=列)