Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R CLUTO文件术语矩阵到tm文件术语矩阵_R_Text Mining_Tm_Cluto - Fatal编程技术网

R CLUTO文件术语矩阵到tm文件术语矩阵

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 解决方案

我有一个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);
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(文档=行,术语=列)