# Example data frame
my_data <- dummy_data(1000)
# Define titles and footnotes. If you want to add hyperlinks you can do so by
# adding "link:" followed by the hyperlink to the main text.
set_titles("This is title number 1 link: https://cran.r-project.org/",
"This is title number 2",
"This is title number 3")
set_footnotes("This is footnote number 1",
"This is footnote number 2",
"This is footnote number 3 link: https://cran.r-project.org/")
# Output frequencies tables
my_data |> frequencies(sex)
my_data |> frequencies(c(age, education),
weight = weight)
# Also works with characters
my_data |> frequencies("sex")
my_data |> frequencies(c("age", "education"),
weight = "weight")
# Applying
sex. <- discrete_format(
"Total" = 1:2,
"Male" = 1,
"Female" = 2)
my_data |> frequencies(sex,
formats = (sex = sex.))
# Split frequencies by expressions of another variable
my_data |> frequencies(sex, by = education)
# Get a list with two data tables for further usage
result_list <- my_data |> frequencies(sex, formats = (sex = sex.))
# Output in text file
my_data |> frequencies(sex, output = "text")
# Output to Excel
my_data |> frequencies(sex, output = "excel")
# Individual styling can also be passed directly
my_style <- excel_output_style(header_back_color = "0077B6",
font = "Times New Roman")
my_data |> frequencies(sex, output = "excel", style = my_style)
# To save a table as xlsx file you have to set the path and filename in the
# style element
# Example files paths
table_file <- tempfile(fileext = ".xlsx")
# Note: Normally you would directly input the path ("C:/MyPath/") and name ("MyFile.xlsx").
set_style_options(save_path = dirname(table_file),
file = basename(table_file),
sheet_name = "MyTable")
my_data |> frequencies(sex, output = "excel")
# Manual cleanup for example
unlink(table_file)
# Global options are permanently active until the current R session is closed.
# There are also functions to reset the values manually.
reset_style_options()
reset_qol_options()
close_file()
Run the code above in your browser using DataLab