recode_df_with_config: Recode Dataframe With Config This function replaces values in...

View source: R/recode_column_values.R

recode_df_with_configR Documentation

Recode Dataframe With Config This function replaces values in a character column. If the Config has "replace_values" field, this will be the mapping used. If the parameter list has a "deafult_replace", anything not in the replace values list will be replaced by this value. If the Config has a "na_replace" field NA values will be replaced by this.

Description

It is assumed that this table has been run through concatenate_df_list_columns_with_config, as columns of type character, and those that were of list:character will be recoded.

Usage

recode_df_with_config(tbl, config)

Arguments

tbl

A tibble

data <- dplyr::tribble( ~col1, ~col2, "a", "c", "a", "d", "b", NA )

config

A list with a named list named "columns" that has an entry for each column needed in the tibble. Each column must have a "name", field. If the config has a "recode" field, this function will be used. The recode field should be a named list with the following optional fields:

  • "replace_values"

  • "na_replace"

  • "deafult_replace"

    config <- list( "columns" = list( "col1" = list( "name" = "col1", "type" = "character", "recode" = list( "replace_values" = list("a" = "A") ) ), "col2" = list( "name" = "col2", "type" = "character", "recode" = list( "replace_values" = list("c" = "C"), "na_replace" = "Missing", "default_replace" = "Other" ) ) )


Sage-Bionetworks/projectliveModules documentation built on June 26, 2022, 1:11 a.m.