epi_clean_label: Apply Factor Levels and Labels Based on a Lookup Table

View source: R/epi_clean_label.R

epi_clean_labelR Documentation

Apply Factor Levels and Labels Based on a Lookup Table

Description

This function takes a dataframe and a lookup dataframe that contains the mapping of factors' levels and labels for specific variables. It applies these levels and labels to the corresponding variables in the target dataframe.

Usage

epi_clean_label(data_df, lookup_df)

Arguments

data_df

A dataframe to which factor levels and labels will be applied. This dataframe should contain columns that match the variable names specified in the lookup dataframe.

lookup_df

A lookup dataframe containing at least three columns: variable, level, and label, where variable is the name of the column in data_df for which levels and labels are specified, level are the factor levels (as character), and label are the corresponding labels for these levels.

Value

A modified version of data_df with specified columns converted to factors with levels and labels as defined in lookup_df.

Examples

# Assume data_df is already loaded and contains 'ORIGEN' and 'SECTOR' columns
# Assume lookup_df is set up with columns 'variable', 'level', and 'label'
# result_df <- epi_clean_label(data_df, lookup_df)


AntonioJBT/episcout documentation built on Dec. 1, 2024, 4:07 a.m.