Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

Describe

Descriptive statistics.


Description

Descriptive statistics.

Usage

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

Arguments

data

Data frame or numeric vector.

nsmall

Number of decimal places of output. Default is 2.

all.as.numeric

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

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).

save.file

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

width

Width (in "inch") of the saved plot. Default is 8.

height

Height (in "inch") of the saved plot. Default is 6.

dpi

DPI (dots per inch) of the saved plot. Default is 500.

Value

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

See Also

Examples

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

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

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

d=as.data.table(psych::bfi)
d[,`:=`(
  gender=as.factor(gender),
  education=as.factor(education),
  E=MEAN(d, "E", 1:5, rev=c(1,2), likert=1:6),
  A=MEAN(d, "A", 1:5, rev=1, likert=1:6),
  C=MEAN(d, "C", 1:5, rev=c(4,5), likert=1:6),
  N=MEAN(d, "N", 1:5, likert=1:6),
  O=MEAN(d, "O", 1:5, rev=c(2,5), likert=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

Broadly Useful Convenient and Efficient R Functions

v0.6.2
GPL-3
Authors
Han-Wu-Shuang Bao [aut, cre]
Initial release
2021-04-08

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.