Skip to contents

This function converts columns to factors and recodes their levels based on the provided mapping. It can process both specific column names and columns with common base names.

Usage

recode_and_convert_column(df, col_name, mapping)

Arguments

df

A data frame containing the columns to be recoded and converted.

mapping

A list containing the old and new levels for each column or base name.

stop_on_missing_col

A logical value. If TRUE, the function stops if a column is missing in the data frame. If FALSE, it skips the missing columns.

Value

The data frame with the specified columns recoded and converted to factors.