【问题标题】:Converting a Term Document Matrix to a Term Document Matrix supported by tm library将术语文档矩阵转换为 tm 库支持的术语文档矩阵
【发布时间】:2017-02-07 02:40:44
【问题描述】:

我有一个 csv 文件,其中我的所有文档都以术语文档矩阵形式和分类变量作为情感。 我想使用tm 的功能(术语频率等)。鉴于我开始使用的数据,有没有办法做到这一点?

# given:

dtm = read.csv(file_path, na.strings="") 
dtm$rating = as.factor(dtm$rating)

str(dtm)
# 'data.frame': 2000 obs. of  2002 variables:
# $ ID           : int  1 2 3 4 5 6 7 8 9 10 ...
# $ abl          : int  0 0 0 0 0 0 0 0 0 0 ...
# ...

head(dtm)
#ID abl absolut absorb accept 
#1  1   0       0      0      
#2  2   0       0      1

# I'd like to achieve...
tdm <- TermDocumentMatrix(dtm,
                          control = list(removePunctuation = TRUE,
                                         stopwords = TRUE))

【问题讨论】:

  • dtm 已经是词频的data.frame 了吗?

标签: r


【解决方案1】:

你能用as.TermDocumentMatrix(df, weighting = weightTf)(在R包里tm)来做你想做的事吗?

【讨论】:

    猜你喜欢
    • 2018-05-04
    • 1970-01-01
    • 2021-07-27
    • 2015-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-19
    • 2018-04-29
    相关资源
    最近更新 更多