简体   繁体   中英

How To Save a Variable as a Data Frame in R

I am new to R and programming in general and am trying to create a program that will collect and analyze data from twitter. The code I am using is below:

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)

I am trying to figure out how to save Pat1 as a data frame so that Pat1 is a data table from which you take Pat1$Patientcomment as variable.

When I run the program now, I get the following result:

> 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

Try Sent[[all]] . See if it helps.

I am working on a sentiment analysis. For polarities, I used the qdap package and having the same error for all reviews - for single sentences as well as for single words... why this happening?

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

Error in derive_pubkey(key) :
RAW() can only be applied to a 'raw', not a 'list'

I consulted this article . Is there something I missed? derive_pubkey(key) - what does this mean?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM