【发布时间】:2023-01-30 22:24:39
【问题描述】:
info <- paste("select count (*) as total
from ANNUAL_CROP a
where a.CROP_TYPE='Rye' and a.GEO = 'Canada'
and a.YEAR = '%1968' ")
query <- sqlQuery(conn,info,believeNRows = FALSE)
query
请问如何在子值条件下在 R 中编写 sqlQuery,原始数据集将年份变量作为字符,我需要查询 CROP_TYPE='Rye' 和 a.GEO = 'Canada' 的行总数 和 a.YEAR = 1968
这是原始数据集 Annual_crops 的样本
【问题讨论】:
-
如果我理解正确的话,你想将你的 SQL 查询“翻译”成 R 代码,对吧?
-
有关执行此操作的 R 代码,请参阅summarize by group。我的猜测(我没有花时间转录你的图片数据,请只提供图片,meta.stackoverflow.com/a/285557(和xkcd.com/2116)),类似于
with(mtcars, tapply(disp, list(cyl, gear), FUN = length))或dplyr::count(mtcars, cyl gear)。