View source: R/quick-summary.R
| sum1 | R Documentation |
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.
sum1(
...,
by = NULL,
data = NULL,
detail = FALSE,
digits = 2,
missing = c("ifany", "no", "always"),
overall = TRUE,
show = TRUE,
console = FALSE
)
... |
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,
|
data |
Optional data frame. When omitted, active data is used. |
detail |
Logical. If |
digits |
Decimal places. |
missing |
Missing handling for grouping variables: |
overall |
Logical; display the unstratified overall summary. |
show |
Logical; open the formatted result in the Viewer. Default |
console |
Logical; also print the traditional result in the Console. Default |
Invisibly returns an object of class r4vn_quick.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.