Skip to contents

Rename columns of a dataset with desired names

Usage

rename_vars(data, tobe_asis)

Arguments

data

a dataframe with columns to rename

tobe_asis

a named list of the old column names assigned to the new column names ie. list('new column names' = 'old column names')

Value

original dataframe containing new columns of the renamed columns with tidyverse code attached

See also

Author

Zhaoming Su

Examples

renamed <- rename_vars(iris, list(
    sepal_length = "Sepal.Length",
    sepal_width = "Sepal.Width",
    petal_length = "Petal.Length",
    petal_width = "Petal.Width"
))
cat(code(renamed))
#> iris |> dplyr::rename(sepal_length = "Sepal.Length", sepal_width = "Sepal.Width",   petal_length = "Petal.Length", petal_width = "Petal.Width")
head(renamed)
#>   sepal_length sepal_width petal_length petal_width Species
#> 1          5.1         3.5          1.4         0.2  setosa
#> 2          4.9         3.0          1.4         0.2  setosa
#> 3          4.7         3.2          1.3         0.2  setosa
#> 4          4.6         3.1          1.5         0.2  setosa
#> 5          5.0         3.6          1.4         0.2  setosa
#> 6          5.4         3.9          1.7         0.4  setosa