Learn R Programming

rcoder (version 0.3.0)

make_recode_query: Make a recoding call from linked codings

Description

This creates a function that accepts a vector and recodes it from the information provided in a `linked_coding_df`. Usually this is intended for package authors who want to operate at the recoding relational table level (e.g. mapping multiple codings to one). Most end users should use [recode_vec()] instead.

Usage

make_recode_query(linked_codings, from = 1, to_suffix = "to", ...)

Value

A function with single argument when applied to an input vector will recode the vector appropriately

Arguments

linked_codings

A `linked_coding_df`

from

A character or integer that selects the correct original coding. Defaults to 1, the first linked coding.

to_suffix

The suffix used to signify which columns refer to values to which the vector will be recoded

...

Any other parameters passed onto the recoding function selector

Examples

Run this code
cdng_old <- coding(code("Yes", 1), code("No", 2))
cdng_new <- coding(code("Yes", 1), code("No", 0))
recode_func <- make_recode_query(link_codings(cdng_new, cdng_old))

vec <- sample(1:2, 20, replace = TRUE)
recode_func(vec)

Run the code above in your browser using DataLab