parse_cat_spec: Parse a category specification

Description Usage Arguments Value Examples

View source: R/data_io.R

Description

The input is a category specification such as "2 1 3 4 -4". The output is a list with named elements that maps the original categories (which are interpreted as string variables onto sequential integers that run from 0 to M, where there are M+1 categories. The curly brackets indicate that categories "3" and "4" should be collapsed together to form a single, final category. For the category specification ([cat_spec]) "2 1 3 4 -4", the mapping between original and final categories is:

"2" -> 0 "1" -> 1 "3" -> 2 "4" -> 2 "-4" -> 3

Note how the string variable "-4" is the final category, even though it would be the first variable were it interpreted as the number -4.

Usage

1
parse_cat_spec(cat_spec)

Arguments

cat_spec

The category specification (e.g., "2 1 3 4 -4")

Value

A list that maps the original string categories onto final integer categories

Examples

1
2
3
# Call parse_cat_spec to create the category mapping
cat_map <- yada::parse_cat_spec("2 1 {3 4} -4")
print(cat_map)

MichaelHoltonPrice/yada documentation built on Sept. 19, 2021, 11:27 p.m.