### connected price data:
set.seed(123)
dt1 <- rdata(R=4, B=1, N=3)
dt1[, is.connected(r=region, n=product)] # true
dt1[, neighbors(r=region, n=product, simplify=TRUE)]
dt1[, gaps(r=region, n=product)]
dt1[, pairs(r=region, n=product)]
dt1[, properties(r=region, n=product)]
### non-connected price data:
dt2 <- data.table::data.table(
"region"=c("a","a","h","b","a","a","c","c","d","e","e","f",NA),
"product"=c(1,1,"bla",1,2,3,3,4,4,5,6,6,7),
"price"=runif(13,5,6),
stringsAsFactors=TRUE)
dt2[, is.connected(r=region, n=product)] # false
with(dt2, neighbors(r=region, n=product))
dt2[, properties(region, product)]
# note that the first two observations are treated as one
# while the observation [NA,7] is dropped. Observation [a,2]
# is still included even though it does not provide valueable
# information for interregional comparisons (the product is
# observed in only one region)
# connect the price data:
dt2[connect(r=region, n=product),]
Run the code above in your browser using DataLab