Description Usage Arguments Value Examples
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.
1 | apply_cat_spec(v_str, cat_spec)
|
v_str |
The vector of original string categories |
cat_spec |
The category specification |
The vector of new, integer categories
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.