使用 dplyr 翻译 R 代码中的 SQL 语句

Translate SQL statement in R code using dplyr

我需要帮助使用 dplyr 将关于此数据集 https://www.kaggle.com/datasets/hugomathien/soccer 的 SQL 语句转换为 r 代码。 SQL 语句是:

SELECT Match.date ,Team.team_long_name, Team.team_short_name ,Match.home_team_goal
FROM Team JOIN Match
ON Match.home_team_api_id = Team.team_api_id
WHERE Match.match_api_id = 492476;

我试过的r代码是:

con <- DBI::dbConnect(RSQLite::SQLite(), "data/database.sqlite")
library(tidyverse)
library(DBI)
match<-tbl(con,"Match")
team<-tbl(con,"Team")
table_4.2<-match %>%
  filter(match_api_id=492476) %>%
  select(date,home_team_goal,home_team_api_id) %>%
  left_join(team)

我收到这个错误:

dplyr::common_by() 中的错误: ! by 必需,因为数据源没有公共变量。 运行 rlang::last_error() 查看错误发生的地方。

Run rlang::last_error() to see where the error occurred.

使用代码:

library(tidyverse)
Team %>%
  left_join(Match, by = c(home_team_api_id = 'team_api_id')) %>%
  filter(match_api_id == 492476) %>%
  select(date, team_long_name, team_short_name, home_team_goal)