sum1: Quick numeric descriptive statistics

View source: R/quick-summary.R

sum1R Documentation

Quick numeric descriptive statistics

Description

Displays console descriptive statistics for one or more numeric variables. With nested grouping such as by = c(sex, agegroup), results are first separated by sex and then summarized for each age group within sex.

Usage

sum1(
  ...,
  by = NULL,
  data = NULL,
  detail = FALSE,
  digits = 2,
  missing = c("ifany", "no", "always"),
  overall = TRUE,
  show = TRUE,
  console = FALSE
)

Arguments

...

One or more numeric variables. An explicit data frame may be supplied as the first unnamed argument.

by

Optional grouping variables supplied as one bare name, c(sex, agegroup), or vars(sex, agegroup).

data

Optional data frame. When omitted, active data is used.

detail

Logical. If FALSE, reports N, missing, mean, SD, median, minimum, and maximum. If TRUE, also reports SE, variance, quartiles, IQR, range, coefficient of variation, skewness, and kurtosis.

digits

Decimal places.

missing

Missing handling for grouping variables: "no" excludes records missing any grouping variable; "ifany" and "always" retain observed missing strata. Missing numeric values are always excluded from calculations and counted in the Missing column.

overall

Logical; display the unstratified overall summary.

show

Logical; open the formatted result in the Viewer. Default TRUE.

console

Logical; also print the traditional result in the Console. Default FALSE.

Value

Invisibly returns an object of class r4vn_quick.

Examples

d <- data.frame(
  sex = factor(rep(c("Female", "Male"), each = 4)),
  agegroup = factor(rep(c("<40", "40+"), 4)),
  age = c(25, 42, 31, 55, 29, 48, 36, 61),
  bmi = c(20.1, 23.5, 21.7, 25.2, 22.4, 26.1, NA, 24.8)
)
usedf(d, quiet = TRUE)

sum1(age)
sum1(age, bmi)
sum1(age, by = sex)
sum1(age, bmi, by = c(sex, agegroup))
sum1(age, detail = TRUE)

usedf(clear = TRUE, quiet = TRUE)

# Extended usage examples

d <- data.frame(
  sex = factor(rep(c("Female", "Male"), each = 6)),
  agegroup = factor(rep(c("<40", "40+"), 6)),
  province = factor(rep(c("HCMC", "Other"), each = 3, times = 2)),
  age = c(25, 42, 31, 55, 29, 48, 36, 61, 33, 47, 52, 40),
  bmi = c(20.1, 23.5, 21.7, 25.2, 22.4, 26.1, NA, 24.8, 23.0, 27.1, 22.8, 24.2),
  sbp = c(110, 128, 118, 145, 121, 138, 125, 151, 130, 142, 136, 129)
)
usedf(d)

# One or several numeric variables
sum1(age)
sum1(age, bmi, sbp)

# One and several nested grouping variables
sum1(age, by = sex)
sum1(age, bmi, by = c(sex, agegroup))
sum1(age, bmi, by = c(province, sex, agegroup))

# Detailed statistics
sum1(age, bmi, detail = TRUE)

# Missing grouping strata, decimal places, and overall display
sum1(age, by = sex, missing = "no", digits = 1)
sum1(age, by = sex, missing = "ifany", overall = FALSE)

# Retain results without printing and use explicit data
result <- sum1(age, bmi, by = sex, show = FALSE)
result$variables[[1]]$overall
sum1(d, age, bmi, by = c(sex, agegroup))
sum1(age, bmi, data = d)


R4VN documentation built on Sept. 30, 2026, 5:13 p.m.