| desc_var | R Documentation |
Returns a dataframe with one row per group.
desc_var(y, group = NULL, data = NULL, digits = 3)
y |
A numeric vector of values, a column name (character string or unquoted) if |
group |
Optional grouping variable, if not provided computed for the full data.
Ignored if |
data |
Optional data frame containing the variable(s). |
digits |
Number of decimal places to round to. Default is 3. |
The dependent variable ('y') must be numeric. If you pass an existing non-numeric variable (e.g., character, factor), 'desc_var()' will stop with a clear error indicating that the variable must be numeric.
A data frame with one row per group (or one row if no group is specified) containing:
group: Group identifier
mean: Mean
sd: Standard deviation
se: Standard error
median: Median
min: Minimum
max: Maximum
mode: Most frequent value
freq_mode: Frequency of mode
mode2: 2nd most frequent value
freq_mode2: Frequency of 2nd mode
n.total: Number of observations
n.missing: Number of observations with missing (NA) values
n.unique: Number of unique values
Columns may also carry a "label" attribute, which provides a short
human-readable description of each column.
# With grouping
df <- data.frame(y = rnorm(100), group = rep(c("A", "B"), 50))
desc_var(y, group, data = df)
# Without grouping (full dataset)
desc_var(y, data = df)
# Direct vectors
y <- rnorm(100)
group <- rep(c("A", "B"), 50)
desc_var(y, group)
# With custom decimal places
desc_var(y, group, data = df, digits = 2)
# Using formula syntax: y ~ x
desc_var(y ~ group, data = df)
# Using formula syntax with multiple grouping variables: y ~ x1 + x2
df2 <- data.frame(y = rnorm(200), x1 = rep(c("A", "B"), 100), x2 = rep(c("X", "Y"), each = 100))
desc_var(y ~ x1 + x2, data = df2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.