Create sample description table (also referred to as "Table 1").
Usage
report_sample(
data,
group_by = NULL,
centrality = "mean",
select = NULL,
exclude = NULL,
weights = NULL,
total = TRUE,
digits = 2,
...
)
Arguments
- data
A data frame for which descriptive statistics should be created.
- group_by
Character vector, indicating the column for possible grouping of the descriptive table.
- centrality
Character, indicates the statistics that should be calculated for numeric variables. May be
"mean"
(for mean and standard deviation) or"median"
(for median and median absolute deviation) as summary.- select
Character vector, with column names that should be included in the descriptive table.
- exclude
Character vector, with column names that should be excluded from the descriptive table.
- weights
Character vector, indicating the name of a potential weight-variable. Reported descriptive statistics will be weighted by
weight
.- total
Add a
Total
column.- digits
Number of decimals.
- ...
Arguments passed to or from other methods.
Examples
library(report)
report_sample(iris[, 1:4])
#> # Descriptive Statistics
#>
#> Variable | Summary
#> ------------------------------------
#> Mean Sepal.Length (SD) | 5.84 (0.83)
#> Mean Sepal.Width (SD) | 3.06 (0.44)
#> Mean Petal.Length (SD) | 3.76 (1.77)
#> Mean Petal.Width (SD) | 1.20 (0.76)
report_sample(iris, select = c("Sepal.Length", "Petal.Length", "Species"))
#> # Descriptive Statistics
#>
#> Variable | Summary
#> -------------------------------------
#> Mean Sepal.Length (SD) | 5.84 (0.83)
#> Mean Petal.Length (SD) | 3.76 (1.77)
#> Species [setosa], % | 33.3
#> Species [versicolor], % | 33.3
#> Species [virginica], % | 33.3
report_sample(iris, group_by = "Species")
#> # Descriptive Statistics
#>
#> Variable | setosa (n=50) | versicolor (n=50) | virginica (n=50) | Total (n=150)
#> ---------------------------------------------------------------------------------------------
#> Mean Sepal.Length (SD) | 5.01 (0.35) | 5.94 (0.52) | 6.59 (0.64) | 5.84 (0.83)
#> Mean Sepal.Width (SD) | 3.43 (0.38) | 2.77 (0.31) | 2.97 (0.32) | 3.06 (0.44)
#> Mean Petal.Length (SD) | 1.46 (0.17) | 4.26 (0.47) | 5.55 (0.55) | 3.76 (1.77)
#> Mean Petal.Width (SD) | 0.25 (0.11) | 1.33 (0.20) | 2.03 (0.27) | 1.20 (0.76)