Left and right joins

Joining Data with data.table in R

Scott Ritchie

Postdoctoral Researcher in Systems Genomics

Left joins

Add information from the right data.table to the left data.table

merge(x = demographics, y = shipping, by = "name", all.x = TRUE)

Joining Data with data.table in R

Right joins

Add information from the left data.table to the right data.table

merge(x = demographics, y = shipping, by = "name", all.y = TRUE)

Joining Data with data.table in R

Right joins - Left joins

# Right join
merge(x = demographics, y = shipping, by = "name", all.y = TRUE)

# Same as
merge(x = shipping, y = demographics, by = "name", all.x = TRUE)
Joining Data with data.table in R

Default values

  • Default values for all, all.x and all.y are FALSE in the merge() function

  • Look up function argument defaults using help("merge")

Joining Data with data.table in R

Exercise instructions

Left join shipping to demographics:

merge(demographics, shipping, by = "name", all.x = TRUE)

Right join shipping to demographics:

merge(demographics, shipping, by = "name", all.y = TRUE)
Joining Data with data.table in R

Let's practice!

Joining Data with data.table in R

Preparing Video For Download...