从R中的语料库或数据框中删除英语以外的语言

从R中的语料库或数据框中删除英语以外的语言,r,inner-join,text-mining,sentiment-analysis,tm,R,Inner Join,Text Mining,Sentiment Analysis,Tm,我目前正在寻找对25000条YouTube评论进行一些文本挖掘,这些评论是我使用tuber包收集的。我是一个非常新的编码和所有这些不同的信息在那里,这可能是有点压倒性的时候。所以我已经清理了我创建的语料库: # Build a corpus, and specify the source to be character vectors corpus <- Corpus(VectorSource(comments_final$textOriginal)) # Convert to lowe

我目前正在寻找对25000条YouTube评论进行一些文本挖掘,这些评论是我使用
tuber
包收集的。我是一个非常新的编码和所有这些不同的信息在那里,这可能是有点压倒性的时候。所以我已经清理了我创建的语料库:

# Build a corpus, and specify the source to be character vectors
corpus <- Corpus(VectorSource(comments_final$textOriginal))

# Convert to lower case
corpus <- tm_map(corpus, content_transformer(tolower))

# Remove URLs
removeURL <- function(x) gsub("http[^[:space:]]*", "", x)
corpus <- tm_map(corpus, content_transformer(removeURL))

# Remove anything other than English letters or space 
removeNumPunct <- function(x) gsub("[^[:alpha:][:space:]]*", "", x) 
corpus <- tm_map(corpus, content_transformer(removeNumPunct))

# Add extra stopwords
myStopwords <- c(stopwords('english'),"im", "just", "one","youre", 
"hes","shes","its","were","theyre","ive","youve","weve","theyve","id")

# Remove stopwords from corpus
corpus <- tm_map(corpus, removeWords, myStopwords)

# Remove extra whitespace
corpus <- tm_map(corpus, stripWhitespace)

# Remove other languages or more specifically anything with a non "a-z""0-9" character
corpus <- tm_map(corpus, content_transformer(function(s){
gsub(pattern = '[^a-zA-Z0-9\\s]+',
   x = s,
   replacement = " ",
   ignore.case = TRUE,
   perl = TRUE)}))

# Replace word elongations using the textclean package by Tyler Rinker. 
corpus <- tm_map(corpus, replace_word_elongation)

# Creating data frame from corpus 
corpus_asdataframe<-data.frame(text = sapply(corpus, as.character),stringsAsFactors = FALSE)

# Due to pre-processing some rows are empty. Therefore, the empty rows should be removed.

# Remove empty rows from data frame and "NA's"
corpus_asdataframe <-corpus_asdataframe[!apply(is.na(corpus_asdataframe) | corpus_asdataframe == "", 1, all),]
corpus_asdataframe<-as.data.frame(corpus_asdataframe)

# Create corpus of clean data frame
corpus <- Corpus(VectorSource(corpus_asdataframe$corpus_asdataframe))
#构建一个语料库,并将源指定为字符向量
语料库