The example I present here is a little silly, yet it illustrates how to join tables with
data.table in R.
Mapping old data to new data
Categories in general are never fixed, they always change at some point. And then the trouble starts with the data. For example not that long ago we didn't distinguish between smartphones and dumbphones, or video on demand and video rental shops.
I would like to back track price change data for smartphones and online movie rental shops, assuming that their earlier development can be set to the categories they were formerly part of, namely mobile and video rental shops to create indices.
Here is my toy data:
I'd like to create price indices for all products and where data for the new product categories is missing, use the price changes of the old product category.
data.table package helps here. I start with my original data, convert it into a
data.table and create mapping tables. That allows me to add the old product with its price change to the new product. The trick here is to set certain columns as key. Two data tables with the same key can easily be joined. Once I have the price changes for products and years the price index can be added. The plot illustrates the result, the R code is below.
Read more »