如何解决R tm 函数不会删除停用词
我目前正在开展一个基于色情数据集的项目,需要将标题按频率排序,然后绘制结果。但是,当我运行代码时,其中包含某些停用词,例如我想删除的“and”。我尝试使用以下方法删除:
tm_map(corpus,removeWords,stopwords('en'))
但这不起作用并以类似的错误结束 UseMethod("removeWords",x) 中的错误: 没有适用于 'removeWords' 的方法应用于类 "c('SimpleCorpus','Corpus')" 的对象
这是我目前的代码
xhamster <- read_csv("xhamster.csv")
head(xhamster) # Need to change upload_date into a date column,then add new column containing year
xhamster$upload_date<-as.Date(xhamster$upload_date,format="%d/%m/%Y")
xhamster$Year<-year(ymd(xhamster$upload_date)) #Adds new column containing just the year
xhamster$Year<-as.integer(xhamster$Year) # Changing new Year variable into an interger
head(xhamster) # Check changes made correctly
Yr2007<-xhamster%>%
filter_at(vars(Year),any_vars(.%in%c("2007")))
Corpus07<-Corpus(VectorSource(Yr2007$title))
TextDoc_dtm <- TermDocumentMatrix(Corpus07)
dtm_m <- as.matrix(TextDoc_dtm)
# Sort by descearing value of frequency
dtm_v <- sort(rowSums(dtm_m),decreasing=TRUE)
dtm_d <- data.frame(word = names(dtm_v),freq=dtm_v)
# Display the top 5 most frequent words
head(dtm_d,10)
谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。