Learn R Programming

whep (version 0.3.0)

harmonize_simple: Harmonize rows labeled "simple" by summing values

Description

Sum value for rows where type == "simple". This covers both 1:1 and N:1 item mappings, since in both cases the values are simply summed. The results are grouped by item_code_harm, year and any additional grouping columns supplied via ....

Usage

harmonize_simple(data, ...)

Value

A tibble with columns:

  • item_code_harm: Numeric, code for harmonized item.

  • year: Numeric, year of observation.

  • value: Numeric, summed value of observation.

  • and any additional grouping columns.

Arguments

data

A data frame containing at least columns:

  • item_code_harm: Numeric, code for harmonized item.

  • year: Numeric, year of observation.

  • value: Numeric, value of observation.

  • type: String, harmonization type. Only "simple" rows are used.

...

Additional grouping columns supplied as bare names.

Examples

Run this code
# 1:1 mapping: one original item -> one harmonized code
df_one_to_one <- tibble::tribble(
  ~item_code_harm, ~year, ~value, ~type,
  1,               2000,  10,     "simple",
  2,               2000,   3,     "simple",
  1,               2001,  12,     "simple",
  2,               2001,   5,     "simple"
)
harmonize_simple(df_one_to_one)

# N:1 mapping: multiple items map to the same code
df_many_to_one <- tibble::tribble(
  ~item_code_harm, ~year, ~value, ~type,
  1,               2000,   4,     "simple",
  1,               2000,   6,     "simple",
  2,               2000,   3,     "simple"
)
harmonize_simple(df_many_to_one)

# With an extra grouping column (e.g. country)
df_grouped <- tibble::tribble(
  ~item_code_harm, ~year, ~value, ~type,    ~country,
  1,               2000,   4,     "simple", "usa",
  1,               2000,   6,     "simple", "usa",
  1,               2000,   9,     "simple", "germany",
  2,               2000,   3,     "simple", "usa"
)
harmonize_simple(df_grouped, country)

# Rows with type != "simple" are ignored
df_mixed <- tibble::tribble(
  ~item_code_harm, ~year, ~value, ~type,
  1,               2000,  10,     "simple",
  1,               2000,  99,     "1:n",
  2,               2000,   3,     "simple"
)
harmonize_simple(df_mixed)

Run the code above in your browser using DataLab