label_to_colnames: Use variable labels as column names

Description Usage Arguments Value Examples

View source: R/label_to_colnames.R

Description

This function sets variable labels as column names, to use "labelled data" also for those functions that cannot cope with labelled data by default.

Usage

1

Arguments

x

A data frame.

...

Optional, unquoted names of variables that should be selected for further processing. Required, if x is a data frame (and no vector) and only selected variables from x should be processed. You may also use functions like : or tidyselect's select-helpers. See 'Examples'.

Value

x with variable labels as column names. For variables without variable labels, the column name is left unchanged.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
data(iris)

iris <- var_labels(
  iris,
  Petal.Length = "Petal length (cm)",
  Petal.Width = "Petal width (cm)"
)

colnames(iris)
plot(iris)

colnames(label_to_colnames(iris))
plot(label_to_colnames(iris))

Example output

[1] "Sepal.Length" "Sepal.Width"  "Petal.Length" "Petal.Width"  "Species"     
[1] "Sepal.Length"      "Sepal.Width"       "Petal length (cm)"
[4] "Petal width (cm)"  "Species"          

sjlabelled documentation built on May 11, 2021, 5:08 p.m.