R函数将文本文件转换为文档术语矩阵
我的文本文件有三列,分别是文档id、术语id和术语频率。是否有一个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
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)
的结果)、预期输出,您尝试了哪些代码行以及以何种方式失败。