【发布时间】:2019-05-19 00:07:59
【问题描述】:
我正在尝试在 R 中重新创建以下 SAS 代码
PROC SQL;
create table counts_2018 as
select a.*, b.cell_no
from work.universe201808 a, work.selpar17 b
where a.newregionxx = b.lower_region2
and a.froempment >= b.lower_size
and a.froempment <= b.upper_size
and a.frosic07_2 >= b.lower_class2
and a.frosic07_2 <= b.upper_class2;
QUIT;
实际上,它的作用是将 selpar17 中的 cell_no 分配给 universe201808 中的数据,基于 strong>代码中列出的所有 6 个条件。不满足这些条件的数据,因此不会有一个 cell_no 分配给它,不包括在决赛桌。
到目前为止,我发现的文档/答案都从一个步骤开始,即两个数据帧由一个公共变量合并,然后执行 sqldf select。我没有公共列,因此无法合并我的数据框。
【问题讨论】:
-
您应该能够将该查询放入
sqldf,只需进行最少的更改。删除work.部分、proc sql;和;quit;,并以select ...开始查询。那么,你试过了吗?是否有错误,如果有,是什么错误? -
你能提供我选择两个数据帧的第一行代码吗?我能找到的文档只显示了一个数据框的参数
-
它接受像proc sql这样的普通SQL查询,
counts_2018 <- sqldf('select a.*, b.cell_no from universe201808 a, selpar17 b where a.newregionxx = b.lower_region2 and a.froempment >= b.lower_size and a.froempment <= b.upper_size and a.frosic07_2 >= b.lower_class2 and a.frosic07_2 <= b.upper_class2')应该可以工作。 -
啊,我错过了 ' ' 。唯一的问题是“rsqlite_send_query(conn@ptr, statement) 中的错误:靠近“where”:语法错误“
-
好的,那你就得分享你的数据了,否则没人能重现这个问题。
标签: sql r sas inner-join sqldf