在本书后面的tydy-text上获得n-gram:http://tidytextmining.com/ngrams.html
代码:
library(tidyr)
bigrams_separated <- austen_bigrams %>%
separate(bigram, c("word1", "word2"), sep = " ")
bigrams_filtered <- bigrams_separated %>%
filter(!word1 %in% stop_words$word) %>%
filter(!word2 %in% stop_words$word)
# new bigram counts:
bigram_counts <- bigrams_filtered %>%
count(word1, word2, sort = TRUE)
我收到错误:
Warning: Error in : 'sep' is not an exported object from 'namespace:dplyr'
答案 0 :(得分:0)
尝试此代码不加载tidyr:
bigrams_separated <- austen_bigrams %>%
mutate(word1 = sub(" .*", "", bigram),
word2 = sub(".* ", "", bigram))
答案 1 :(得分:0)
我遇到了相同的错误,似乎可以通过指定tidyr :: separate()来解决