【发布时间】:2023-01-26 23:34:10
【问题描述】:
我正在做一个包括 Twitter 抓取的项目。
问题:我似乎无法删除所有以“https”开头的单词。
我的代码:
library(twitteR)
library(tm)
library(RColorBrewer)
library(e1017)
library(class)
library(wordcloud)
library(tidytext)
scraped_tweets <- searchTwitter('Silk Sonic - leave door open', n = 10000, lang='en')
# get text data from tweets
scraped_text <- sapply(scraped_tweets, function(x){x$getText()})
# removing emojis and characters
scraped_text <- iconv(scraped_text, 'UTF-8', 'ASCII')
scraped_corpus <- Corpus(VectorSource(scraped_text))
doc_matrix <- TermDocumentMatrix(scraped_corpus, control = list(removePunctuation=T,
stopwords = c('https','http', 'sonic',
'silk',stopwords('english')),
removeNumbers = T,tolower = T))
# convert object into a matrix
doc_matrix <- as.matrix(doc_matrix)
# get word counts
head(doc_matrix,1)
words <- sort(rowSums(doc_matrix), decreasing = T)
dm <- data.frame(word = names(words), freq = words)
# wordcloud
wordcloud(dm$word, dm$freq, random.order = F, colors = brewer.pal(8, 'Dark2'))
我添加了“https”和“http”标签,但没有用。 我当然可以使用 gsub 清理输出,但这与我仍然将链接名称的其余部分作为输出不同。
我有什么想法可以做到这一点吗?
提前致谢。
【问题讨论】:
标签: r twitter sentiment-analysis stop-words