gpt4 book ai didi

mysql - 用于执行 SQL 查询的 R 和 R-SQL API

转载 作者:行者123 更新时间:2023-11-29 19:05:01 25 4
gpt4 key购买 nike

对于作业,我需要“使用 SQL 提取上一步中这 3 个用户 ID 下的 Twitter 消息表中的所有推文”。我目前对在 R 中使用向量 x 从 MySQL 获取推文信息感到困惑。

我不断收到此错误消息“.local(conn, statements, ...) 中的错误: 未使用的参数(c(18949452, 34713362, 477583514))。”

    #use SQL to get a list of unique user id in twitter message table as a 
#vector in R.
res <- dbSendQuery(con, statement = "select user_id from
twitter_message")
user_id <- dbFetch(res)
user_id

nrow(user_id)
#randomly selects : use R to randomly generate 3 user id

x <- user_id[sample(nrow(user_id), 3, replace = FALSE, prob = NULL),]
x

res2 = dbSendQuery(con, statement = 'SELECT twitter_message WHERE
user_id =',x)
tweets <- dbFetch(res2)
tweets

最佳答案

x 是一个向量,因此您也许应该在循环中使用 dbSendQuery 函数。对于 x 中的每个元素,在 dbSendQuery 语句中传递其值。这有道理吗?

关于mysql - 用于执行 SQL 查询的 R 和 R-SQL API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43574262/

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