【问题标题】:How to convert sql statement into dplyr notation?如何将 sql 语句转换为 dplyr 表示法?
【发布时间】:2021-09-15 12:21:29
【问题描述】:

我很难将 sql 语句转换为 dplyr。 假设我有以下 sql 语句:

select * from table1 t1 
left join table2 t2 on t1.id1 = t2.id2
where t2.id is null

dplyr 表示法是:

data <- table1 %>%
  left_join(table2, by = c('id1' = 'id2') %>%
  filter(is.null(id2))

但是它不起作用。 如何修改我的dplyr 语句以对应上述sql语句?

【问题讨论】:

  • 也许这有帮助? dbplyr.tidyverse.org
  • 我认为你需要is.na 而不是is.null。试试%&gt;% filter(is.na(id2))

标签: sql r join dplyr


【解决方案1】:

这个问题可以通过anti_join解决:

data<- table1 %>%
anti_join(table2, by = c('id1' = 'id2')

【讨论】:

    猜你喜欢
    • 2022-07-22
    • 2021-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-29
    • 1970-01-01
    • 2013-04-19
    相关资源
    最近更新 更多