descriptive.statistics | R Documentation |
This function computes descriptive statistics for specified variables in a dataset, optionally grouped by certain categorical variables. The function returns a tidy data frame containing the summaries of the selected variables, including relevant statistics such as mean, standard deviation, and median.
descriptive.statistics(
data,
vars = NULL,
groups = NULL,
use.labels = T,
digits = 4
)
data |
A data frame containing the variables for which descriptive statistics should be calculated. |
vars |
A character vector or symbol specifying the variables for which descriptive statistics will be computed. If NULL, all variables in the data frame will be used. |
groups |
A character vector or symbol specifying one or more grouping variables. If NULL, no grouping will be performed. |
use.labels |
A logical value indicating whether to use variable labels. Default is TRUE. |
digits |
An integer specifying the number of decimal places to round the numeric results. Default is 4. |
A data frame containing the descriptive statistics for the specified variables.
# Load example dataset
data(mtcars)
# Get descriptive statistics for all variables
descriptive.statistics(mtcars)
# Get descriptive statistics for specific variables grouped by a factor
descriptive.statistics(mtcars, vars = c("mpg", "hp"), groups = "cyl")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.