rename_from: Rename elements from dictionary

rename_fromR Documentation

Rename elements from dictionary

Description

Renames the elements of a vector or list from a dictionary, leaving unmatched names untouched by default.

Usage

rename_from(x, dict, default = names(x))

Arguments

x

Object whose elements are to be renamed.

dict

A named character vector or list of strings where names are the old and the values are the new names.

default

Value(s) used when names aren't matched by any name in dict. Recycled to the length of x.

Value

x with elements renamed according to dict.

Examples

mtcars |> pal::rename_from(dict = c(mpg  = "Miles/(US) gallon",
                                    cyl  = "Number of cylinders",
                                    disp = "Displacement (cu.in.)",
                                    hp   = "Gross horsepower",
                                    drat = "Rear axle ratio",
                                    wt   = "Weight (1000 lbs)",
                                    qsec = "1/4 mile time",
                                    vs   = "Engine (0 = V-shaped, 1 = straight)",
                                    am   = "Transmission (0 = automatic, 1 = manual)",
                                    gear = "Number of forward gears",
                                    carb = "Number of carburetors",
                                    not_there = "Yikes!"))

salim-b/pal documentation built on Feb. 28, 2025, 6:51 p.m.