apply_cat_spec: Apply a category specification to an input vector of original...

Description Usage Arguments Value Examples

View source: R/data_io.R

Description

v_str is a vector of original string categories. cat_spec is a cateogry specification (see [parse_cat_spec]). Apply the category specification to each element of v_str to yield a new vector v_int, which gives the integer category values.

Usage

1
apply_cat_spec(v_str, cat_spec)

Arguments

v_str

The vector of original string categories

cat_spec

The category specification

Value

The vector of new, integer categories

Examples

1
2
3
4
5
6
7
8
# Call apply_cat_spec to assign category specification to trait string
v_str <- c("a",NA,"d","b","c",NA,"d","a")  # vector of string categories
cat_spec <- "a c d b"  # order of categories

# Expected application: a=0, c=1, d=2, b=3
# Therefore, expected output: c(0,NA,2,3,1,NA,2,0)
v_int <- apply_cat_spec(v_str, cat_spec)
print(v_int)

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