如何在R中将变量保存为数据帧

我是R的新手并且编程一般,我正在尝试创建一个程序来收集和分析来自twitter的数据.我使用的代码如下:

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

最佳答案 尝试发送[[全部]].看看它是否有帮助.

点赞