# example codes:
ids <- c("CP01","CP011","CP012","CP0111","CP0112")
# derive lowest level of COICOP tree from top to bottom:
tree(ids) # (CP0111,CP0112,CP012) at lowest level
# or just flag lowest level:
tree(ids, flag=TRUE)
# still same codes because weights add up:
tree(id=ids, w=c(0.2,0.08,0.12,0.05,0.03))
# now (CP011,CP012) because weights do not correctly add up at lower levels:
tree(id=ids, w=c(0.2,0.08,0.12,0.05,0.01))
# again (CP011,CP012) because maximum COICOP level limited to 3 digits:
tree(id=c(ids,"01121"),
w=c(0.2,0.08,0.12,0.02,0.06,0.06),
settings=list(max.lvl=3))
# merge (or fix) COICOP tree over groups:
tree(id=c("TOTAL","CP01","CP02","CP011","CP012",
"TOTAL","CP01","CP02","CP011"),
by=c(1,1,1,1,1, 2,2,2,2),
w=c(1,0.3,0.7,0.12,0.18, 1,0.32,0.68,0.15))
# for by=1, the lowest level would be (CP011,CP012,CP02).
# however, CP012 is missing for by=2. therefore, the merged
# COICOP tree consists of (CP01,CP02) at the lowest level.
Run the code above in your browser using DataLab