#' Get a data frame of variable names and labels from a dataset
#'
#' @param dset A data frame
#'
#' @return a data frame with three columns: variable names (vars), variable
#' labels (var_labels), and the number of missing values (num_missing)
#' @export
#'
#' @examples
#' vars_labels(iris)
var_labels <- function(dset){
# Get the labels
var_lables <-
map(dset, ~ ifelse(is.null(attr(.x, "label")),
"None",
attr(.x, "label"))) %>%
unlist()
# Get the number of missing values
num_missing <-
map(dset, ~ sum(is.na(.x))) %>%
unlist()
# get the variable names
vars <- names(dset)
data_frame(vars=vars, var_lables = var_lables, num_missing = num_missing)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.