gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 04:51:26 25 4
gpt4 key购买 nike

我是 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

最佳答案

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

关于r - 如何在 R 中将变量保存为数据帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40809870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com