0

我搜索了问题并能够在我的第一组命令中替换 •。但是当我申请我的语料库时,它不起作用,仍然出现。语料库有 6570 个元素,2.3mb,所以它似乎是有效的。

> x <- ". R Tutorial"
> gsub("•","",x)
[1] ". R Tutorial"

> removeSpecialChars <- function(x) gsub("•","",x)
> corpus2=tm_map(corpus2, removeSpecialChars)
> print(corpus2[[6299]][1])
[1] "• R tutorial • success– october"
> ##remove special characters
4

1 回答 1

0

对于以更直接的方式处理语料库对象的替代方案,这又如何呢?

require(quanteda)
require(magrittr)

corpus3 <- corpus(c("• R Tutorial", "More of these • characters •", "Tricky •!"))

# remove the character from the tokenized corpus
tokens(corpus3)
## tokens from 3 documents.
## text1 :
## [1] "R"        "Tutorial"
## 
## text2 :
## [1] "More"       "of"         "these"      "characters"
## 
## text3 :
## [1] "Tricky" "!"  
tokens(corpus3) %>% tokens_remove("•")
## tokens from 3 documents.
## [1] "R"        "Tutorial"
## text1 :
## 
## text2 :
## [1] "More"       "of"         "these"      "characters"
## 
## text3 :
## [1]] "Tricky" "!"  

# remove the character from the corpus itself
texts(corpus3) <- gsub("•", "", texts(corpus3), fixed = TRUE)
texts(corpus3)
##         text1                        text2                        text3 
## " R Tutorial" "More of these  characters "                   "Tricky !" 
于 2017-03-22T16:44:35.067 回答