当试图复制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包含的tweet数据。
所以我试了一下:
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我试图传递两个输入的向量版本来匹配,但都没有效果。有人有更好的主意吗?
发布于 2016-11-16 15:52:42
不确定,但我认为你的问题在这里:
tidy_tweets_sw <- filter(!word %in% stop_words$word, str_detect(tidy_tweets, "[a-z]"))filter完全不知道您想要过滤什么,这应该是可行的:
tidy_tweets_sw <- tidy_tweets %>% filter(!word %in% stop_words$word, str_detect(tidy_tweets, "[a-z]"))发布于 2016-11-16 15:46:57
您需要将filter语句中的数据作为第一个参数。
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(tidy_tweets, !(word %in% stop_words$word), str_detect(tidy_tweets, "[a-z]"))https://stackoverflow.com/questions/40635529
复制相似问题