get_name_labs {labelr}R Documentation

Return Look-up Table of Variable Names and Name Labels

Description

For a name-labeled data.frame, get_name_labs returns a derivative data.frame that lists each variable and its variable name label.

Note: gnl is a compact alias for get_name_labs: they do the same thing, and the former is easier to type

Usage

get_name_labs(data, vars = NULL)

gnl(data, vars = NULL)

Arguments

data

a data.frame.

vars

a character vector with the name(s) of any specific variable(s) (If NULL, returned data.frame will contain all variable name labels).

Value

A two-column data.frame, consisting of "var" and "lab" columns, where each row corresponds to a unique variable (column) from the user- supplied data.frame.

Examples

# create a data set
df <- mtcars

# variable names and their labels
names_labs_vec <- 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"
)

# assign variable labels
df <- add_name_labs(df,
  vars = names(names_labs_vec),
  labs = names_labs_vec
)

# see what we have
get_name_labs(df)

[Package labelr version 0.1.7 Index]