2016-11-25 80 views
4

我是R的新手,一般编程,并且正在尝试创建一个程序来收集和分析来自twitter的数据。我使用的代码如下:如何在R中保存一个变量作为数据帧

install.packages(c("devtools", "rjson", "bit64", "httr")) 

library(devtools) 

library(twitteR) 

APIkey <- "xxxxxxxxxxxxxxxxxxxxxx" 
APIsecret <- "xxxxxxxxxxxxxxxxxxxxxxxxx" 
accesstoken <- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 
accesstokensecret <- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 

setup_twitter_oauth(APIkey,APIsecret,accesstoken,accesstokensecret) 


Pat1$Patientsentiment <- tolower (Pat1$Patientcomment) 

library(qdap) 

Sent<-polarity(Pat1$Patientcomment, grouping.var = Pat1$Pat.NUMBER, 

      positive.list = positive.words, 

      negative.list = negative.words, 

      negation.list = negation.words, 

      amplification.list = increase.amplification.words, 

      rm.incomplete = FALSE, digits = 3) 

RPatient_Polarity <- data.frame(Sent$all) 

我试图找出如何PAT1保存为一个数据帧,这样PAT1是从中拿PAT1 $ Patientcomment作为变量的数据表。

当我现在运行的程序,我得到以下结果:

> library(devtools) 
> library(twitteR) 
> APIkey <- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 
> APIsecret <- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 
> accesstoken <- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 
> accesstokensecret <- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 
> setup_twitter_oauth(APIkey,APIsecret,accesstoken,accesstokensecret) 
[1] "Using direct authentication" 
Error in check_twitter_oauth() : OAuth authentication error: 
This most likely means that you have incorrectly called  
setup_twitter_oauth()' 
> Pat1$Patientsentiment <- tolower (Pat1$Patientcomment) 
> library(qdap) 
> Sent<-polarity(Pat1$Patientcomment, grouping.var = Pat1$Pat.NUMBER, 
+     
+    positive.list = positive.words, 
+     
+    negative.list = negative.words, 
+     
+    negation.list = negation.words, 
+     
+    amplification.list = increase.amplification.words, 
+     
+    rm.incomplete = FALSE, digits = 3) 
Error in derive_pubkey(key) : 
    RAW() can only be applied to a 'raw', not a 'list' 
> RPatient_Polarity <- data.frame(Sent$all) 
Error in data.frame(Sent$all) : object 'Sent' not found 

回答

1

尝试Sent[[all]]。看看它是否有帮助。

0

我正在进行情绪分析。对于极性来说,我使用了qdap软件包,并且对于所有评论都有相同的错误 - 对于单个句子以及单个单词... 为什么会发生这种情况?

library(qdap)  
polarity("I love to eat") 

错误derive_pubkey(键):
RAW()只能应用于 '生',而不是 '名单'

我咨询this article。有什么我错过了吗? derive_pubkey(key) - 这是什么意思?

相关问题