[英]text analysis - looking to remove lowercase words from my corpus. Can I use gsub? Using tm_map to clean-up
[英]I can't remove • and some other special characters such as '- using tm_map
我搜索所有问题,并能够在第一组命令中替换掉•。 但是,当我申请我的语料库时,它不起作用,•仍然出现。 语料库有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
对于以更直接的方式与语料库对象一起工作的替代方法呢?
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 !"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.