Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.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函数将文本文件转换为文档术语矩阵_R_Text Mining - Fatal编程技术网

R函数将文本文件转换为文档术语矩阵

R函数将文本文件转换为文档术语矩阵,r,text-mining,R,Text Mining,我的文本文件有三列,分别是文档id、术语id和术语频率。是否有一个R函数将此数据转换为文档术语矩阵 例如 df <- read.table(header=T, text='"doc" "term" "freq" 1 "foo" 1 1 "bar" 2 2 "hello" 1 2 "world" 2') library(tm) dtm <- as.DocumentTermMatrix(xtabs(freq~doc+term, df), weighting=weightTf) as.ma

我的文本文件有三列,分别是文档id、术语id和术语频率。是否有一个R函数将此数据转换为文档术语矩阵

例如

df <- read.table(header=T, text='"doc" "term" "freq"
1 "foo" 1
1 "bar" 2
2 "hello" 1
2 "world" 2')
library(tm)
dtm <- as.DocumentTermMatrix(xtabs(freq~doc+term, df), weighting=weightTf)
as.matrix(dtm)
#     Terms
# Docs bar foo hello world
#    1   2   1     0     0
#    2   0   0     1     2
例如,
df

df <- read.table(header=T, text='"doc" "term" "freq"
1 "foo" 1
1 "bar" 2
2 "hello" 1
2 "world" 2')
library(tm)
dtm <- as.DocumentTermMatrix(xtabs(freq~doc+term, df), weighting=weightTf)
as.matrix(dtm)
#     Terms
# Docs bar foo hello world
#    1   2   1     0     0
#    2   0   0     1     2
df请阅读-问题应提供输入数据(例如添加
dput(mydata)
的结果)、预期输出、您尝试的代码行以及失败的方式。请阅读-问题应提供输入数据(例如添加
dput(mydata)
的结果)、预期输出,您尝试了哪些代码行以及以何种方式失败。