Describe: Descriptive statistics.

View source: R/bruceR-stats_1_basic.R

DescribeR Documentation

Descriptive statistics.

Description

Descriptive statistics.

Usage

Describe(
  data,
  all.as.numeric = TRUE,
  digits = 2,
  file = NULL,
  plot = FALSE,
  upper.triangle = FALSE,
  upper.smooth = "none",
  plot.file = NULL,
  plot.width = 8,
  plot.height = 6,
  plot.dpi = 500
)

Arguments

data

Data frame or numeric vector.

all.as.numeric

TRUE (default) or FALSE. Transform all variables into numeric (continuous).

digits

Number of decimal places of output. Defaults to 2.

file

File name of MS Word (.doc).

plot

TRUE or FALSE (default). Visualize the descriptive statistics using GGally::ggpairs().

upper.triangle

TRUE or FALSE (default). Add (scatter) plots to upper triangle (time consuming when sample size is large).

upper.smooth

"none" (default), "lm", or "loess". Add fitting lines to scatter plots (if any).

plot.file

NULL (default, plot in RStudio) or a file name ("xxx.png").

plot.width

Width (in "inch") of the saved plot. Defaults to 8.

plot.height

Height (in "inch") of the saved plot. Defaults to 6.

plot.dpi

DPI (dots per inch) of the saved plot. Defaults to 500.

Value

Invisibly return a list with (1) a data frame of descriptive statistics and (2) a ggplot2 object if plot=TRUE.

See Also

Corr

Examples

set.seed(1)
Describe(rnorm(1000000), plot=TRUE)

Describe(airquality)
Describe(airquality, plot=TRUE, upper.triangle=TRUE, upper.smooth="lm")

# ?psych::bfi
Describe(psych::bfi[c("age", "gender", "education")])

d = as.data.table(psych::bfi)
added(d, {
  gender = as.factor(gender)
  education = as.factor(education)
  E = .mean("E", 1:5, rev=c(1,2), range=1:6)
  A = .mean("A", 1:5, rev=1, range=1:6)
  C = .mean("C", 1:5, rev=c(4,5), range=1:6)
  N = .mean("N", 1:5, range=1:6)
  O = .mean("O", 1:5, rev=c(2,5), range=1:6)
})
Describe(d[, .(age, gender, education)], plot=TRUE, all.as.numeric=FALSE)
Describe(d[, .(age, gender, education, E, A, C, N, O)], plot=TRUE)


bruceR documentation built on June 22, 2024, 12:26 p.m.