HierarchyFix: Change the hierarchy table to follow the standard

View source: R/HierarchyCompute.R

HierarchyFixR Documentation

Change the hierarchy table to follow the standard

Description

Make sure that variable names and sign coding follow an internal standard. Level may be computed automatically

Usage

HierarchyFix(
  hierarchy,
  hierarchyVarNames = c(mapsFrom = "mapsFrom", mapsTo = "mapsTo", sign = "sign", level =
    "level"),
  autoLevel = TRUE
)

Arguments

hierarchy

data frame with hierarchy table

hierarchyVarNames

variable names

autoLevel

When TRUE, level is computed by automatic method

Value

data frame with hierarchy table

Author(s)

Øyvind Langsrud

Examples

# Make input data by changing variable names and sign coding.
h <- SSBtoolsData("FIFA2018ABCD")[, 1:3]
names(h)[1:2] <- c("from", "to")
minus <- h$sign < 0
h$sign <- "+"
h$sign[minus] <- "-"

# Run HierarchyFix - Two levels created
HierarchyFix(h, c(mapsFrom = "from", mapsTo = "to", sign = "sign"))

# Extend the hierarchy table
h2 <- rbind(data.frame(from = c("Oceania", "Asia", "Africa", "America", "Europe"),
                       to = "World", sign = "+"),
           data.frame(from = c("World", "Europe"),
                      to = "nonEurope", sign = c("+", "-")), h)

# Run HierarchyFix - Three levels created
HierarchyFix(h2, c(mapsFrom = "from", mapsTo = "to", sign = "sign"))


SSBtools documentation built on Oct. 30, 2024, 5:09 p.m.