R:使用TermDocumentMatrix保留大写字母

问题描述 投票:0回答:1

我想用wordcloud包创建一个wordcloud。我的问题是我想在单词的开头保留大写字母,但是所有字母都会自动转换为小写字母。

据我所知,这是在使用TermDocumentMatrix功能时发生的。是否有可能防止该函数将所有字母都转换为小写?

r uppercase lowercase
1个回答
0
投票

通过在控制列表中指定TermDocumentMatrix,可以防止tolower=FALSE将所有内容都转换为小写。由于您没有提供任何数据,因此我将用tm软件包中提供的示例数据进行说明。

library(wordcloud)
library(tm)
data(crude)

tdm = TermDocumentMatrix(crude, 
    control=list(removePunctuation=T, tolower=F, stopwords=T))
WordFreq = slam::row_sums(tdm[tdm$dimnames$Terms, ])
FrequentWords = tail(sort(WordFreq), 20)
wordcloud(names(FrequentWords), FrequentWords)

Word Cloud

© www.soinside.com 2019 - 2024. All rights reserved.