The merge function

Menggabungkan Data dengan data.table di R

Scott Ritchie

Postdoctoral Researcher in Systems Genomics

Joins

  • Concept of joins come from database query languages (e.g. SQL).

  • Four standard joins:

    • inner
    • full
    • left
    • right
  • All four can be done using merge()

Menggabungkan Data dengan data.table di R

Inner join

Only keep observations that have information in both data.tables

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

Menggabungkan Data dengan data.table di R

The by argument

Use by to avoid repeated typing of the same column name

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

Menggabungkan Data dengan data.table di R

Full join

Keep all observations that are in either data.table

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

Menggabungkan Data dengan data.table di R

Let's practice!

Menggabungkan Data dengan data.table di R

Preparing Video For Download...