如何使用R将文件的相关部分转换为语料库
我是一个使用R的初学者,目前正在处理一个包含多列的文件。我想专注于一列(csv文件中标记的文本),创建一个语料库,然后更改文本列中的文本,使其全部为小写,删除标点等等 以下代码是我目前掌握的代码:如何使用R将文件的相关部分转换为语料库,r,tm,R,Tm,我是一个使用R的初学者,目前正在处理一个包含多列的文件。我想专注于一列(csv文件中标记的文本),创建一个语料库,然后更改文本列中的文本,使其全部为小写,删除标点等等 以下代码是我目前掌握的代码: # Import text data ALL_tweets_df <- read.csv("All_tweets.csv", stringsAsFactors = FALSE) library(tm) # View the structure of tweets str(ALL_twee
# Import text data
ALL_tweets_df <- read.csv("All_tweets.csv", stringsAsFactors = FALSE)
library(tm)
# View the structure of tweets
str(ALL_tweets_df)
# Print out the number of rows in tweets
nrow(ALL_tweets_df)
# Isolate text from tweets: All_tweets
ALL_tweets_df <- ALL_tweets_df$text
#converts the relevant part of your file into a corpus
mycorpus<-Corpus(VectorSource(ALL_tweets_df$text))
# change to lower case, remove stop words, remove punctuation
mycorpus2 = tm_map(mycorpus, tolower)
mycorpus3 = tm_map(mycorpus2, removeWords, stopwords("english"))
mycorpus4 = tm_map(mycorpus3, removePunctuation)
#导入文本数据
所有tweets\u df我想命令所有tweets\u df谢谢,这就解决了。我现在正试图用以下代码将其转换回数据帧:mycorpus5前面的答案可能会在这里有所帮助。。。