f_summary {rfriend} | R Documentation |
Summarize a Data Frame with Grouping Variables
Description
Computes summary statistics (e.g., mean, standard deviation, median, etc.) for a specified column ("character string") in a data frame, grouped by one or more grouping variables in that data frame ("character strings"). Summary parameters can be customized and the results can be exported to an 'Excel' file.
Usage
f_summary(
data,
data.column,
...,
show_n = TRUE,
show_mean = TRUE,
show_sd = TRUE,
show_se = TRUE,
show_min = TRUE,
show_max = TRUE,
show_median = TRUE,
show_Q1 = TRUE,
show_Q3 = TRUE,
digits = 2,
export_to_excel = FALSE,
close_generated_files = FALSE,
open_generated_files = TRUE,
output_file = NULL,
output_dir = NULL,
save_in_wdir = FALSE,
open_excel = TRUE,
check_input = TRUE,
eval_input = FALSE,
digits_excel = NULL,
detect_int_col = TRUE
)
Arguments
data |
A 'data.frame', 'data.table' or 'tibble', i.e. input data to be summarized. |
data.column |
A character string, vector or list with characters. The name of the column(s) in |
... |
One or more character strings specifying the grouping variables in |
show_n |
Logical. If |
show_mean |
Logical. If |
show_sd |
Logical. If |
show_se |
Logical. If |
show_min |
Logical. If |
show_max |
Logical. If |
show_median |
Logical. If |
show_Q1 |
Logical. If |
show_Q3 |
Logical. If |
digits |
Integer. Round to the number of digits specified. If |
export_to_excel |
Logical. If |
close_generated_files |
Logical. If |
open_generated_files |
Logical. If |
output_file |
Character string specifying the name of the output file. Default is "dataname_summary.xlsx". |
output_dir |
Character string specifying the name of the directory of the output file. Default is |
save_in_wdir |
Logical. If |
open_excel |
Logical. If |
check_input |
If |
eval_input |
Logical. If |
digits_excel |
Integer. Round cells in the excel file to the number of digits specified. If |
detect_int_col |
Logical. If |
Details
The function computes the following summary statistics for the specified column:
-
n
: number of observations -
mean
: mean -
sd
: standard deviation -
se
: standard error of the mean -
min
: minimum value -
max
: maximum value -
median
: median -
Q1
: first quartile -
Q3
: third quartile
Each of these summary statistics can be removed by setting e.g. show_n = FALSE
, The results are grouped by the specified grouping variables and returned as a data frame. If export_to_excel
is set to TRUE
, the results are saved as an 'Excel' file in the working directory with a dynamically generated filename.
Value
A data frame containing the computed summary statistics, grouped by the specified variables. This data frame can be automatically saved as an 'Excel' file using export_to_excel = TRUE
.
Author(s)
Sander H. van Delden plantmind@proton.me
Examples
# Example usage:
# Create a summary of mtcars for data column hp grouped by cyl and gear,
# and remove Q1 and Q3 from the output.
# Note that variable can be written as "hp" or as hp. Only data.frame must be data (no quotes)
summary_mtcars <- f_summary(mtcars, "hp", "cyl", "gear", show_Q1 = FALSE, show_Q3 = FALSE)
print(summary_mtcars)
# Create a summary for iris
summary_iris <- f_summary(iris, Sepal.Length, Species)
# Print the a table with column width of 10 characters and table length of 70 characters
print(summary_iris, col_width = 10, table_width = 70)