【发布时间】:2016-11-16 15:08:31
【问题描述】:
当试图重现http://tidytextmining.com/twitter.html 中的示例时,出现了问题。
基本上我想对这部分代码进行改编
library(tidytext)
library(stringr)
reg <- "([^A-Za-z_\\d#@']|'(?![A-Za-z_\\d#@]))"
tidy_tweets <- tweets %>%
mutate(text = str_replace_all(text, "https://t.co/[A-Za-z\\d]+|http://[A-Za-z\\d]+|&|<|>|RT", "")) %>%
unnest_tokens(word, text, token = "regex", pattern = reg) %>%
filter(!word %in% stop_words$word,
str_detect(word, "[a-z]"))
为了保留 stop_Word 包含的推文数据框。
所以我尝试了这个:
tidy_tweets <- tweets %>%
mutate(text = str_replace_all(text, "https://t.co/[A-Za-z\\d]+|http://[A-Za-z\\d]+|&|<|>|RT", "")) %>%
unnest_tokens(word, text, token = "regex", pattern = reg)
tidy_tweets_sw <- filter(!word %in% stop_words$word, str_detect(tidy_tweets, "[a-z]"))
但这不起作用,因为我收到以下错误消息:
Error in match(x, table, nomatch = 0L) :
'match' requires vector arguments
我尝试传递两个输入的矢量版本以进行匹配,但无济于事。 有人有更好的主意吗?
【问题讨论】:
-
tidytext 通常在小插曲中使用
anti_join(stop_words)。