rename_from_labels.Rd
These functions work with an attribute label
. Which has been
introduced by other packages (e.g. haven
) and is implemented into the
R-Studiio environment.
add_label(x, value)
rename_from_labels(
data,
keep = FALSE,
pattern = "{name}: {label}",
max_char = NULL
)
get_labels(data, keep = FALSE, pattern = "{name}: {label}", max_char = NULL)
A data frame or a vector.
Either a single character string when x
is a vector or a named
list (columnname = label
) with character strings when x
is a
data.frame.
A data.frame.
If TRUE, new names are a combination of var names and label names.
Pattern for gleu function when keep = TRUE
.
Maximum number of characters for the label.
For add_label: A vector or a data.frame with added label attribute(s).
For rename_from_labels: A data.frame with renamed labels or for get_labels a character vector with label names.
For get_labels
: A names character vector with labels (and columnnames
as names).
wmisc:::mtcars_labeled |> get_labels()
#> 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"