r - 使用数据表左连接
问题描述
我想知道data.table中以下表达式的等价物是什么:
require(nycflights13)
require(data.table)
require(dplyr)
flights_tv <- flights %>% select(year:day, hour, origin, dest, carrier)
left_join_tv <- flights_tv %>% left_join(airports, c("dest" = "faa"))
解决方案
类似的选择data.table
是
library(data.table)
out <- as.data.table(airports)[as.data.table(flights)[, .SD,
.SDcols = c("year", "month", "day", "hour", "origin", "dest", "carrier")],
on = .(faa = dest)]
all.equal(dim(left_join_tv), dim(out))
#[1] TRUE
推荐阅读
- php - 为每个相同的单词放置一个破折号(正则表达式,php)
- c++ - ld:未找到架构 x86_64 的符号 clang:错误
- firebase - 哪个firestore规则可以显示所有带有我的uid的文档?
- javascript - CRUD - 如果页面没有刷新,添加和删除一个接一个地不起作用
- android - 如何使用约束布局设置recyclerview最小高度wrap_content但最大百分比?
- angular - NGRX 路由器成对单元测试
- symfony - Symfony 5.1 如何从其他位置获取控制器
- php - 如何使用 webhook 安全地触发 git pull?
- node.js - wss 通过 nginx 连接到节点 ws 服务器,ERR_CERT_AUTHORITY_INVALID
- c++ - 解析 RapidJSON 时出现错误的地方