knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(studentenstatistikNRW) library(labelled) library(gtsummary)
Select a random table in studententstatistikNRW::tables
:
# https://stackoverflow.com/questions/9057006/getting-strings-recognized-as-variable-names-in-r df <- get( get_table_name( tables |> dplyr::slice_sample(n = 1) |> dplyr::pull(tablename) ) ) df
Show variable labels with labelled::var_label
for all variables:
labelled::var_label( x = df )
labelled::look_for
is meant to help users finding variables in large datasets:
# All variables labelled::look_for( df ) # All variables starting with "BIL" labelled::look_for( df, "BIL" )
For more details:
# Tibble as opposed to default printing labelled::look_for( df, details = "full" ) |> tibble::as_tibble() # List columns as character labelled::look_for( df, details = "full" ) |> labelled::convert_list_columns_to_character()
Use labelled::to_factor
for easy factor conversion:
df_factor <- df |> labelled::to_factor( levels = "labels", ordered = TRUE, sort_levels = "labels", strict = FALSE, # Convert to factor only if all values have a defined label? labelled_only = TRUE # for a data.frame, convert only labelled variables to factors? ) df_factor
df_factor |> gtsummary::tbl_summary()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.