首页 > 解决方案 > 在 R 中将推文转换为文本格式时出错

问题描述

我想使用 R 对 twitter 数据进行情感分析。我的数据集为 dataset.txt,在 R 中,我正在执行以下操作:

library(twitteR) ### for fetching the tweets
library(plyr) ## for breaking the data into manageable pieces
library(ROAuth) # for R authentication
library(stringr) # for string processing
library(ggplot2) # for plotting the results

tweets = read.table("E://dataset.txt",header = TRUE,sep = "," , quote = "\"",dec = ".", fill = TRUE, comment.char = "")
#for converting tweets to text format
tweets_txt = sapply(tweets[],function(x) x$getText())

我在这一行收到错误:

tweets_txt = sapply(tweets[],function(x) x$getText())

错误是:

Error in x$getText : $ operator is invalid for atomic vectors

我在哪里做错了?

我也从水槽生成了这个数据集,然后将它导出到 hive 的表中,然后将其导出为 txt 文件,现在我想使用 R 进行情绪分析

dataset.txt 中的一些文本是:

#SafeSchools
#ज्ञान_का_अखाड़ा ,दुनिया के सब जगह संत रामपालजी का ज्ञान (कबीर)  सुन रहे हे 
RT @Rkumars99: दिल्ली में मनमानी फीस पर स्कूलों का अधिग्रहण हो सकता है तो बच्चे की हत्या पर गुड़गांव में ऐसा क्यों नहीं हो सकता?
@BJP4India…
RT @alokg2k: #SafeSchools
Just wondering if Ryan school owner Pinto's have even cared to talk to Pradyumn's parents to pacify th… 
RT @k_satyarthi: How can we see a child go to school in uniform and return in a coffin? #SafeSchools. 2/3
RT @Gautam_p1251: Several others held a sit-in protest at the police commissioner’s office. #SafeSchools 
RT @hemantvyas6633: #SafeSchools
#ज्ञान_का_अखाड़ा में स्वागत है अखाड़ा परिषद का आओ ओर करो पराजित शास्त्रार्थ में #संतरामपालजीमहाराज को… 
RT @imNSharmaBJP: Congressi Trolling @narendramodi ji should also see this pics.
#RyanInternationalSchool Principle with Rahul Gandhi… 
RT @SatguruGreat: #ज्ञान_का_अखाड़ा में सभी धर्मगुरु बताए सन्त रामपाल जी महाराज से ज्ञान चर्चा के मैदान में क्यों नहीं आये ??
#ThatsWhyNSUI…
RT @Gautam_p1251: This is the worst you can expect after sending your child to school. #SafeSchools 
RT @GANESHYADAV82: #SafeSchools 
#ज्ञान_का_अखाड़ा
 सर्व सोने की लंका थी वो रावण से रान्दिरम , एक पलख मे राज बीरा जे जम के पड़े जंजीरम ।।
सा…

标签: rtwittersentiment-analysis

解决方案


推荐阅读