This function prints an inventory of a dataset, similar to Stata's
varlist
function.
varlist(data)
Input data frame (tibble)
Tibble with the following columns:
name
Variable name
n
Number of non-missing observations
class
Variable class
label
Variable label
# Load mtcars dataset,
# label it, and create missing values
data(mtcars)
df <- mtcars %>%
labelled::set_variable_labels(mpg = "Miles per Gallon",
gear = "Number of Gears") %>%
dplyr::mutate(qsec = dplyr::if_else(am == 1,
true = NA_real_,
false = qsec))
# Show varlist. Note missing values in "qsec".
varlist(df)
#> # A tibble: 11 × 4
#> name n class label
#> <chr> <dbl> <chr> <chr>
#> 1 mpg 32 numeric Miles per Gallon
#> 2 cyl 32 numeric NULL
#> 3 disp 32 numeric NULL
#> 4 hp 32 numeric NULL
#> 5 drat 32 numeric NULL
#> 6 wt 32 numeric NULL
#> 7 qsec 19 numeric NULL
#> 8 vs 32 numeric NULL
#> 9 am 32 numeric NULL
#> 10 gear 32 numeric Number of Gears
#> 11 carb 32 numeric NULL