# sample complete price data:
set.seed(123)
dt1 <- rdata(R=3, B=1, N=5)
# compute jevons and toernqvist index:
dt1[, jevons(p=price, r=region, n=product, base="1")]
dt1[, toernqvist(p=price, r=region, n=product, q=quantity, base="1")]
# compute lowe index using quantities of region 2:
dt1[, lowe(p=price, r=region, n=product, q=quantity, base="1",
settings=list(qbase="2"))]
# add price data:
dt2 <- rdata(R=4, B=1, N=4)
dt2[, "region":=factor(region, labels=4:7)]
dt2[, "product":=factor(product, labels=6:9)]
dt <- rbind(dt1, dt2)
dt[, is.connected(r=region, n=product)] # non-connected now
# compute jevons and toernqvist index:
dt[, jevons(p=price, r=region, n=product, base="1")]
# change base region:
dt[, jevons(p=price, r=region, n=product, base="4")]
Run the code above in your browser using DataLab