在SQL中调用R Dataframe [英] Call R Dataframe in SQL

查看:54
本文介绍了在SQL中调用R Dataframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在SQL中调用R数据帧?例如,我想运行以下命令:

is there any way to call an R dataframe in SQL? For example, I would like to run something like:

SELECT user_id,other_variables FROM table1
WHERE user_id IN('R DATAFRAME' )

其中R数据帧是一些用户ID的简单列表,可以在表1中找到。

where the R dataframe is a simple list of some user id's that can be found in table1.

我只是想知道是否有可能用R或SQL编写这样的东西,如果可以,这怎么做?我知道我可以将R数据帧上传到数据库,但是我没有在数据库中创建自己的表的权限。任何帮助将不胜感激,谢谢。

I was just wondering if something like this is possible, either written in R or SQL and if so, how do this? I know that I could just upload the R dataframe to the database but I do not have permissions to create my own tables in the database. Any help would be greatly appreciated, thank you.

推荐答案

除非使用spark环境或使用R包 sqldf ,否则不能。

Except with spark environment or with the R package sqldf you cannot.

如果仅是ID列表,则可以使用 unlist()

If it's only a list of ids you can use unlist()

sqlQuery (ch,paste0(" 
  select * from my_table 
  where id in (",
  paste(unlist(my_df_Fktable$id), 
  collapse=','),
  ")"
))

这篇关于在SQL中调用R Dataframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆