labeltable: Label Table Function

View source: R/labeltable.R

labeltableR Documentation

Label Table Function

Description

This function output a descriptive table listing, for each value of a given variable, either the label of that value, or all values of another variable associated with that value. The table is output either to the console or as an HTML file that can be viewed continuously while working with data.

Usage

labeltable(
  var,
  ...,
  out = NA,
  count = FALSE,
  percent = FALSE,
  file = NA,
  desc = NA,
  note = NA,
  note.align = NA,
  anchor = NA
)

Arguments

var

A vector. Label table will show, for each of the values of this variable, its label (if labels can be found with sjlabelled::get_labels()), or the values in the ... variables.

...

As described above. If specified, will show the values of these variables, instead of the labels of var, even if labels can be found.

out

Determines where the completed table is sent. Set to "browser" to open HTML file in browser using browseURL(), "viewer" to open in RStudio viewer using viewer(), if available. Use "htmlreturn" to return the HTML code to R, "return" to return the completed variable table to R in data frame form, or "kable" to return it in knitr::kable() form. Combine out = "csv" with file to write to CSV (dropping most formatting). Additional options include "latex" for a LaTeX table or "latexpage" for a full buildable LaTeX page. Defaults to "viewer" if RStudio is running, "browser" if it isn't, or a "kable" passed through kableExtra::kable_styling() defaults if it's an RMarkdown document being built with knitr.

count

Set to TRUE to also report the number of observations for each value of var in the data.

percent

Set to TRUE to also report the percentage of non-missing observation for each value of var in the data.

file

Saves the completed variable table file to HTML with this filepath. May be combined with any value of out, although note that out = "return" and out = "kable" will still save the standard labeltable HTML file as with out = "viewer" or out = "browser"..

desc

Description of variable (or labeling system) to be included with the table.

note

Table note to go after the last row of the table.

note.align

Set the alignment for the multi-column table note. Usually "l", but if you have a long note in LaTeX you might want to set it with "p"

anchor

Character variable to be used to set an anchor link in HTML tables, or a label tag in LaTeX.

Details

Outputting the label table as a help file will make it easy to search through value labels, or to see the correspondence between the values of one variable and the values of another.

Labels that are not in the data will also be reported in the table.

Examples


if(interactive()){
#Input a single labelled variable to see a table relating values to labels.
#Values not present in the data will be included in the table but moved to the end.
library(sjlabelled)
data(efc)
labeltable(efc$e15relat)

#Include multiple variables to see, for each value of the first variable,
#each value of the others present in the data.
data(efc)
labeltable(efc$e15relat,efc$e16sex,efc$e42dep)

#Commonly, the multi-variable version might be used to recover the original
#values of encoded variables
data(USJudgeRatings)
USJudgeRatings$Judge <- row.names(USJudgeRatings)
USJudgeRatings$JudgeID <- as.numeric(as.factor(USJudgeRatings$Judge))
labeltable(USJudgeRatings$JudgeID,USJudgeRatings$Judge)
}

vtable documentation built on Oct. 26, 2023, 5:08 p.m.