recode_with_csv: Recode factor or character variables with a CSV file Will...

View source: R/recode_with_csv.R

recode_with_csvR Documentation

Recode factor or character variables with a CSV file Will take as input a path to a csv file with oldname,newname syntax. Will find each of the oldnames in the column, and replace them for newname.

Description

Recode factor or character variables with a CSV file Will take as input a path to a csv file with oldname,newname syntax. Will find each of the oldnames in the column, and replace them for newname.

Usage

recode_with_csv(
  data,
  csvfile = ".recode",
  old_column,
  new_column = {
     {
         old_column
     }
 }
)

Arguments

data

Dataset to manipulate

csvfile

path to a csv file with oldname, newname syntax

old_column

variable name to edit

new_column

variable name to save the result in. Will overwrite old_column if left blank

Value

mutated dataset

Examples

mtcars |>
mutate(gear_f = factor(gear, labels = c("three", "four","five"))) |>
rename_with_csv(csvfile,gear_f)

lirabenjamin/Ben documentation built on Aug. 6, 2024, 7:11 p.m.