2016-11-25 120 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) - 這是什麼意思?

相關問題