codebook_table {esmtools} | R Documentation |
Create Codebook Table
Description
The codebook_table()
function generates a codebook table for a given dataframe,
providing descriptive statistics and visualizations for each variable.
See an example here: https://preprocess.esmtools.com/pages/90_Codebook_table_esmtools.html.
Usage
codebook_table(
df,
origin_cbook = NULL,
origin_vars = "Variable",
n_unique_thres = 6,
include_txt = FALSE,
include_date = TRUE,
histograms = TRUE,
boxplots = TRUE,
html_output = NULL,
kable_out = TRUE
)
Arguments
df |
The dataframe for which the codebook table is generated. |
origin_cbook |
A dataframe of a hand-maid codebook table that is stored in an csv of xlsx file.
The file must be first imported in the R session.
If the variable containing the basis codebook, the resulting codebook table will include
the original codebook information.
This allows merging and incorporating a hand-made codebook into the output.
Default is |
origin_vars |
A character string specifying the name of the variable column in the |
n_unique_thres |
The threshold for the number of unique values to consider a variable as categorical. Default is 6. |
include_txt |
Logical indicating whether to include text variable statistics in the codebook table.
Default is |
include_date |
Logical indicating whether to include date variable statistics in the codebook table.
Default is |
histograms |
Logical indicating whether to include histograms in the codebook table.
Default is |
boxplots |
Logical indicating whether to include boxplots in the codebook table.
Default is |
html_output |
Define a file name (e.g., "path/to/codebook_table.html") to create an html output version of the codebook table. |
kable_out |
When TRUE, output is in kable version. If FALSE, use DT package. |
Value
A a codebook table generated using kable or the DT package.
Examples
if (interactive()) {
# Load library
library(esmtools)
library(readxl)
# Load the hand-made codebook
path_original <- system.file("extdata", "cbook_part1.xlsx", package = "esmtools")
original_codebook <- read_excel(path_original)
# Create codebook table based on the hand-made codebook and the dataset
codebook_table(df = esmdata_sim, origin_cbook = original_codebook)
}