recode_item: Recode values of a data frame

View source: R/recode_item.R

recode_itemR Documentation

Recode values of a data frame

Description

Recode values of a data frame

Usage

recode_item(data, cols, code_from = NULL, code_to = NULL, retain_code = NULL)

Arguments

data

A data.frame or a data.frame extension (e.g. a tibble).

cols

Columns that need to be recoded. See 'dplyr::dplyr_tidy_select' for available options.

code_from

vector. the order must match with vector for 'code_to'

code_to

vector. the order must match with vector for 'code_from'

retain_code

vector. Specify the values to be retain

Value

An object of the same type as .data. The output has the following properties: 1. Columns except the recoded columns from .data will be preserved 2. Recoded columns

Examples

pre_recoded_df = tibble::tibble(x1 = 1:5, x2 = 5:1)
recoded_df = recode_item(pre_recoded_df, cols = dplyr::contains('x'),
                        code_from = 1:5,
                        code_to = 5:1)


psycCleaning documentation built on Nov. 5, 2023, 9:06 a.m.