Step 4: Create big dataset

Hmm, I need to put all the data into a "flat-file" view

DT[i, j, by]
DT[WHERE | JOIN | ORDER , 
  SELECT | UPDATE , 
  GROUP][...]

Join Territory to the Order

# Specify the columns to join by
setkey(Order     , TerritoryID)
setkey(Territory , TerritoryID)

# Reads as join Territory to the Order table
# Seperate table so we don't have to start again
OrderTerritory <- Territory[Order]

Join Region to the OrderTerritory

# Specify the columns to join by
setkey(OrderTerritory , CountryRegionCode)
setkey(Region         , CountryRegionCode)

# Reads as join Region to the OrderTerritory table
# Will overwrite as it's our desired state
OrderTerritory <- Region[OrderTerritory]


stephlocke/Rtraining documentation built on May 30, 2019, 3:36 p.m.