[英]Can I check the frequencies of predetermined words or phrases in document clustering using R?
我正在使用R中的“ tm”包進行文本挖掘,生成術語文檔矩陣后可以獲得單詞頻率:
freq <- colSums(as.matrix(dtm))
ord <- order(freq)
freq[head(ord)]
# abit acal access accord across acsess
# 1 1 1 1 1 1
freq[tail(ord)]
# direct save month will thank list
# 106 107 116 122 132 154
它只能按順序顯示單詞頻率列表,我想知道是否可以單獨檢查單詞的頻率? 我還可以檢查短語的頻率嗎? 例如,單詞“謝謝”在文本語料庫中出現了多少次,或者該語料庫中出現的短語“聯系電話”的出現頻率是多少?
非常感謝您的任何提示和建議。
我通過tm包中的數據展示了這一點:
library(tm)
data(crude)
dtm <- as.matrix(DocumentTermMatrix(crude))
#find the column that contains the word "demand"
columnindices <- which(colnames(dtm)=="demand")
#how often dooes the word "demand" show up?
sum(dtm[,columnindices])
>6
如果要使用短語來執行此操作,則dtm必須包含這些短語,而不僅僅是大多數情況下使用的單個單詞。 如果有此數據,則過程與單個單詞相同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.