summaryStats: Calculate and format summary statistics

Description Usage Arguments Value Author(s) See Also Examples

Description

These functions are designed to be used when creating summary tables. There is an option to produce LaTeX output (math mode).

Usage

1
2
3
4
5
6
nmissing(x, ...)
percent(logicalvector, dp = 1,
    latex = (getOption("xtable.type") == "latex"))
npercent(logicalvector, ...)
percentConf(logicalvector, dp = 1, ...)
meansd(x, ...)

Arguments

x

a numeric vector (missing values are ignored)

logicalvector

a logical vector (missing values are ignored)

dp

number of decimal places

latex

TRUE for LaTeX output (math mode), FALSE, NULL or logical(0) for plain text output

...

other arguments to pass to formatnum

Value

a character vector containing the formatted summary statistic. percentConf prints the percentage and a confidence interval using the binomial distribution, without percentage signs.

Author(s)

Anoop Shah

See Also

formatnum, formatp, formathr, formatci

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Number and % missing
nmissing(c(1, 2, 3, NA, NA), latex = FALSE)
# "2 (40.0%)"
nmissing(c(1, 2, 3, NA, NA), latex = TRUE)
# "2 (40.0\%)"

# Percentage
percent(c(TRUE, TRUE, FALSE, NA), latex = FALSE)
# "66.7%"
percent(c(TRUE, TRUE, FALSE, NA), latex = TRUE)
# "66.7\%"

# Number and percentage
npercent(c(TRUE, TRUE, FALSE, NA), latex = FALSE)
# "2 (66.7%)"
npercent(c(TRUE, TRUE, FALSE, NA), latex = TRUE)
# "2 (66.7\%)"

# Percentage with 95% confidence interval
percentConf(c(TRUE, TRUE, FALSE, NA), latex = FALSE)
# "66.7 (9.43, 99.2)"
percentConf(c(TRUE, TRUE, FALSE, NA), latex = TRUE)
# "$66.7$ ($9.43$, $99.2$)"

# Mean and standard deviation
meansd(1:100, latex = FALSE)
# "50.5 (29)"
meansd(1:100, latex = TRUE)
# "$50.5$ ($29$)"
meansd(1:100, dp = 5, latex = FALSE)
# "50.50000 (29.01149)"

CALIBERdatamanage documentation built on Nov. 23, 2021, 3 p.m.