Skip to contents

This function creates a measure ID column in a data frame based on selected columns. The measure ID is a string that concatenates the values of the selected columns with hyphens. The measure ID can optionally include the country and survey strings.

Usage

create_measure_id(data, country, survey, cols, include_ISOs = FALSE)

Arguments

data

A data frame to modify.

country

A character string specifying the country of the data.

survey

A character string specifying the survey of the data.

cols

A character vector specifying the names of the columns to include in the measure ID.

include_ISOs

A logical value indicating whether to include the country and survey strings in the measure ID.

Value

A modified data frame with a measure ID column added.

Examples

data <- data.frame(unit_name = c("kg", "g", "lb", "oz"), unit_code = c("KGM", "GRM", "LBR", "ONZ"), 
region = c("A", "B", "C", "D"))
create_measure_id(data, "USA", "NHANES", c("unit_name", "unit_code", "region"), TRUE)
#>   unit_name unit_code region          measure_id
#> 1        kg       KGM      A USA-NHANES-kg-KGM-A
#> 2         g       GRM      B  USA-NHANES-g-GRM-B
#> 3        lb       LBR      C USA-NHANES-lb-LBR-C
#> 4        oz       ONZ      D USA-NHANES-oz-ONZ-D