Vinicius Riffel
Vinicius Riffel

Reputation: 112

Left join using Data Table

I would like to know what is the equivalent of the expression below in 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"))

Upvotes: 0

Views: 62

Answers (1)

akrun
akrun

Reputation: 887881

Similar option in data.table would be

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

Upvotes: 1

Related Questions