Learn R Programming

⚠️There's a newer version (0.99.57) of this package.Take me there.

Tools for Descriptive Statistics and Exploratory Data Analysis

DescTools is an extensive collection of miscellaneous basic statistics functions and comfort wrappers not available in the R basic system for efficient description of data. The author’s intention was to create a toolbox, which facilitates the (notoriously time consuming) first descriptive tasks in data analysis, consisting of calculating descriptive statistics, drawing graphical summaries and reporting the results. The package contains furthermore functions to produce documents using MS Word (or PowerPoint) and functions to import data from Excel.

A considerable part of the included functions can be found scattered in other packages and other sources written partly by Titans of R. The reason for collecting them here, was primarily to have them consolidated in ONE instead of dozens of packages (which themselves might depend on other packages, which are not needed at all), and to provide a common and consistent interface as far as function and arguments naming, NA handling, recycling rules etc. are concerned. Google style guides were used as naming rules (in absence of convincing alternatives). The ‘CamelStyle’ was consequently applied to functions borrowed from contributed R packages as well.

Feedback, feature requests, bug reports and other suggestions are welcome! Please report problems to GitHub issues tracker (preferred), Stack Overflow mentioning DescTools or directly to the maintainer.

Installation

You can install the released version of DescTools from CRAN with:

install.packages("DescTools")

And the development version from GitHub with:

if (!require("remotes")) install.packages("remotes")
remotes::install_github("AndriSignorell/DescTools")

Warning

Warning: This package is still under development. Although the code seems meanwhile quite stable, until release of version 1.0 you should be aware that everything in the package might be subject to change. Backward compatibility is not yet guaranteed. Functions may be deleted or renamed and new syntax may be inconsistent with earlier versions. By release of version 1.0 the “deprecated-defunct process” will be installed.

MS-Office

To make use of MS-Office features, you must have Office in one of its variants installed. All Wrd*, XL* and Pp* functions require the package RDCOMClient to be installed as well. Hence the use of these functions is restricted to Windows systems. RDCOMClient can be installed with:

install.packages("RDCOMClient", repos="http://www.omegahat.net/R")

The omegahat repository does not benefit from the same update service as CRAN. So you may be forced to install a package compiled with an earlier version, which usually is not a problem. Use e.g. for R 3.6.x/R 4.0.x:

url <- "http://www.omegahat.net/R/bin/windows/contrib/3.5.1/RDCOMClient_0.93-0.zip"
url <- "http://www.omegahat.net/R/bin/windows/contrib/4.0/RDCOMClient_0.94-0.zip"
install.packages(url, repos = NULL, type = "binary")

RDCOMClient does not exist for Mac or Linux, sorry.

Authors

Andri Signorell
Helsana Versicherungen AG, Health Sciences, Zurich
HWZ University of Applied Sciences in Business Administration Zurich.

R is a community project. This can be seen from the fact that this package includes R source code and/or documentation previously published by various authors and contributors. Special thanks go to Beat Bruengger, Mathias Frueh, Daniel Wollschlaeger for their valuable contributions and testing. The good things come from all these guys, any problems are likely due to my tweaking. Thank you all!

Maintainer: Andri Signorell

Examples

library(DescTools)
demo(describe, package = "DescTools")
demo(plots, package = "DescTools")

Copy Link

Version

Install

install.packages('DescTools')

Monthly Downloads

79,502

Version

0.99.54

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

February 3rd, 2024

Functions in DescTools (0.99.54)

BartelsRankTest

Bartels Rank Test of Randomness
BarText

Place Value Labels on a Barplot
Base Conversions

Converts Numbers From Binmode, Octmode or Hexmode to Decimal and Vice Versa
AscToChar

Convert ASCII Codes to Characters and Vice Versa
Atkinson

Atkinson Index - A Measure of Inequality.
Arrow

Insert an Arrow Into a Plot
AxisBreak

Place a Break Mark on an Axis
BarnardTest

Barnard's Unconditional Test
Assocs

Association Measures
Asp

Get Aspect Ratio of the Current Plot
Bg

Background of a Plot
BinomCI

Confidence Intervals for Binomial Proportions
BinomRatioCI

Confidence Intervals for the Ratio of Binomial Proportions
BinomCIn

Sample Size for a Given Width of a Binomial Confidence Interval
Benford

Benford's Distribution
BhapkarTest

Bhapkar Marginal Homogeneity Test
BinomDiffCI

Confidence Interval for a Difference of Binomials
BinTree

Binary Tree
BootCI

Simple Bootstrap Confidence Intervals
Between, Outside

Operators To Check, If a Value Lies Within Or Outside a Given Range
BreslowDayTest

Breslow-Day Test for Homogeneity of the Odds Ratios
Canvas

Canvas for Geometric Plotting
BoxCoxLambda

Automatic Selection of Box Cox Transformation Parameter
BreuschGodfreyTest

Breusch-Godfrey Test
BoxCox

Box Cox Transformation
BrierScore

Brier Score for Assessing Prediction Accuracy
BubbleLegend

Add a Legend to a Bubble Plot
BoxedText

Add Text in a Box to a Plot
CartToPol

Transform Cartesian to Polar/Spherical Coordinates and Vice Versa
CCC

Concordance Correlation Coefficient
CohenKappa

Cohen's Kappa and Weighted Kappa
CoefVar

Coefficient of Variation
ColToGrey

Convert Colors to Grey/Grayscale
Coalesce

Return the First Element Not Being NA
Closest

Find the Closest Value
Clockwise

Calculates Begin and End Angle From a List of Given Angles in Clockwise Mode
CatTable

Function to write a table
CohenD

Cohen's Effect Size
CochranQTest

Cochran's Q test
CochranArmitageTest

Cochran-Armitage Test for Trend
CompleteColumns

Find Complete Columns
ColToHex

Convert a Color or a RGB-color Into Hex String
ColToRgb

Color to RGB Conversion
CombPairs

Get All Pairs Out of One or Two Sets of Elements
ColorLegend

Add a ColorLegend to a Plot
ConDisPairs

Concordant and Discordant Pairs
ColToHsv

R Color to HSV Conversion
CollapseTable

Collapse Levels of a Table
CountCompCases

Count Complete Cases
CorPolychor

Polychoric Correlation
ConnLines

Add Connection Lines to a Barplot
Contrasts

Pairwise Contrasts
ColumnWrap

Column Wrap
CountWorkDays

Count Work Days Between Two Dates
Conf

Confusion Matrix And Associated Statistics
CourseData

Get HWZ Datasets
CorPart

Find the Correlations for a Set x of Variables With Set y Removed
Cor

Covariance and Correlation (Matrices)
ConoverTest

Conover's Test of Multiple Comparisons
ConvUnit

Unit Conversion and Metrix Prefixes
Datasets for Simulation

Datasets for Probabilistic Simulation
Cstat

C Statistic (Area Under the ROC Curve)
CrossN

n-dimensional Vector Cross Product
Date Functions

Basic Date Functions
CramerVonMisesTest

Cramer-von Mises Test for Normality
Association measures

Cramer's V, Pearson's Contingency Coefficient and Phi Coefficient
Yule's Q and Y, Tschuprow's T
CronbachAlpha

Cronbach's Coefficient Alpha
Cross

Vector Cross Product
CutQ

Create a Factor Variable Using the Quantiles of a Continuous Variable
CutAge

Create a Factor Variable by Cutting an Age Variable
DoBy

Evaluates a Function Groupwise
Desc

Describe Data
DescToolsOptions

DescTools Options
DoCall

Fast Alternative To The Internal do.call
DigitSum

Calculate Digit Sum
DivCoef

Rao's Diversity Coefficient
DescTools-package

Tools for Descriptive Statistics and Exploratory Data Analysis
DegToRad

Convert Degrees to Radians and Vice Versa
DivCoefMax

Maximal value of Rao's diversity coefficient also called quadratic entropy
Divisors

Calculate Divisors
DrawBezier

Draw a Bezier Curve
Dummy

Generate Dummy Codes for a Factor
DrawBand

Draw Confidence Band
DunnettTest

Dunnett's Test for Comparing Several Treatments With a Control
DunnTest

Dunn's Test of Multiple Comparisons
DrawArc

Draw Elliptic Arc(s)
DrawRegPolygon

Draw Regular Polygon(s)
Dot

Scalar Product
DrawEllipse

Draw an Ellipse
EX

Expected Value and Variance
ExpFreq

Expected Frequencies
Entropy

Shannon Entropy and Mutual Information
DurbinWatsonTest

Durbin-Watson Test
DrawCircle

Draw a Circle
ExtrVal

Distributions of Maxima and Minima
FctArgs

Retrieve a Function's Arguments
Factorize

Prime Factorization of Integers
ErrBars

Add Error Bars to an Existing Plot
Eps

Greenhouse-Geisser And Huynh-Feldt Epsilons
Freq

Frequency Table for a Single Variable
EtaSq

Effect Size Calculations for ANOVAs
Fibonacci

Fibonacci Numbers
Freq2D

Bivariate (Two-Dimensional) Frequency Distribution
FindColor

Get Color on a Defined Color Range
FixToTable

Convert a Text to a Table
Frac

Fractional Part and Maximal Digits of a Numeric Value
Frechet

The Frechet Distribution
Format

Format Numbers and Dates
GenRandGroups

Generate Random Groups
GCD, LCM

Greatest Common Divisor and Least Common Multiple
GetCurrWrd

Get a Handle to a Running Word/Excel Instance
GenExtrVal

The Generalized Extreme Value Distribution
GenPareto

The Generalized Pareto Distribution
GetNewWrd

Create a New Word Instance
GetCalls

Return All Used Functions Within a Function
GeomTrans

Geometric Transformations
FindCorr

Determine Highly Correlated Variables
GeomSn

Geometric Series
FisherZ

Fisher-Transformation for Correlation to z-Score
GTest

G-Test for Count Data
GiniSimpson

Gini-Simpson Coefficient, Gini-Deltas coefficient and Hunter-Gaston Index
Herfindahl

Concentration Measures
GoodmanKruskalTau

Goodman Kruskal's Tau
Gumbel

The Gumbel Distribution
Gompertz

The Gompertz distribution
Gmean

Geometric Mean and Standard Deviation
GoodmanKruskalGamma

Goodman Kruskal's Gamma
Gini

Gini Coefficient
HosmerLemeshowTest

Hosmer-Lemeshow Goodness of Fit Tests
GetNewXL

Create a New Excel Instance
HexToRgb

Convert a Hexstring Color to a Matrix With Three Red/Green/Blue Rows
Hmean

Harmonic Mean and Its Confidence Interval
HoeffD

Matrix of Hoeffding's D Statistics
HuberM

Safe (generalized) Huber M-Estimator of Location
IsPrime

IsPrime Property
HexToCol

Identify Closest Match to a Color Given by a Hexadecimal String
HmsToSec

Convert h:m:s To/From Seconds
ICC

Intraclass Correlations (ICC1, ICC2, ICC3 From Shrout and Fleiss)
HotellingsT2Test

Hotelling's T2 Test
IQRw

The (weighted) Interquartile Range
HodgesLehmann

Hodges-Lehmann Estimator of Location
Some numeric checks

Check a Vector For Being Numeric, Zero Or a Whole Number
IdentifyA

Identify Points in Plot Lying Within a Rectangle or Polygon
InDots

Is a Specific Argument in the Dots-Arguments?
KendallTauB

Kendall's \(\tau_{b}\)
IsValidHwnd

Check Windows Pointer
LOCF

Last Observation Carried Forward
LOF

Local Outlier Factor
JonckheereTerpstraTest

Exact Version of Jonckheere-Terpstra Test
JarqueBeraTest

(Robust) Jarque Bera Test
KendallTauA

Kendall's \(\tau_{a}\)
IsOdd

Checks If An Integer Is Even Or Odd
KappaM

Kappa for m Raters
ImputeKnn

Fill in NA values with the values of the nearest neighbours
KrippAlpha

Krippendorff's Alpha Reliability Coefficient
IsEuclid

Is a Distance Matrix Euclidean?
LehmacherTest

Lehmacher's Test for Marginal Homogenity
LeveneTest

Levene's Test for Homogeneity of Variance
Label, Unit

Label, Unit Attribute of an Object
LinScale

Linear Scaling
LillieTest

Lilliefors (Kolmogorov-Smirnov) Test for Normality
IsDate

Check If an Object Is of Type Date
IsDichotomous

Test If a Variable Contains Only Two Unique Values
KendallW

Kendall's Coefficient of Concordance W
Keywords

List Keywords For R Manual Pages
Lambda

Goodman Kruskal Lambda
MAD

Median Absolute Deviation
List Variety Of Objects

List Objects, Functions Or Data in a Package
LineToUser

Convert Line Coordinates To User Coordinates
LogSt

Started Logarithmic Transformation and Its Inverse
Logit

Generalized Logit and Inverse Logit Function
MADCI

Confidence Intervals for Median Absolute Deviations
Measures of Accuracy

Measures of Accuracy
MHChisqTest

Mantel-Haenszel Chi-Square Test
Mar and Mgp

Set Plot Margins and Distances
Extremes

Kth Smallest/Largest Values
Mean

(Weighted) Arithmetic Mean
Midx

Find the Midpoints of a Numeric Vector
MixColor

Compute the Convex Combination of Two Colors
MeanSE

Standard Error of Mean
Median

(Weighted) Median Value
MeanAD

Mean Absolute Deviation From a Center Point
MosesTest

Moses Test of Extreme Reactions
Mode

Mode, Most Frequent Value(s)
Lc

Lorenz Curve
MeanCIn

Sample Size for a Given Width of a Confidence Interval for a Mean
MeanCI

Confidence Intervals for the Mean
NPV

Short Selection of Financial Mathematical Functions
MeanDiffCI

Confidence Interval For Difference of Means
MedianCI

Confidence Interval for the Median
Nf

As Numeric Factor
NemenyiTest

Nemenyi Test
MoveAvg

Moving Average
ORToRelRisk

Transform Odds Ratio to Relative Risk
Mgsub

Multiple Gsub
MultinomCI

Confidence Intervals for Multinomial Proportions
Order

Distributions of Order Statistics
PMT

Periodic Payment of an Annuity.
OddsRatio

Odds Ratio Estimation and Confidence Intervals
ParseFormula

Parse a Formula and Create a Model Frame
PageTest

Exact Page Test for Ordered Alternatives
PasswordDlg

Password Dialog
PearsonTest

Pearson Chi-Square Test for Normality
ParseSASDatalines

Parse a SAS Dataline Command
MultMerge

Merge Multiple Data Frames
PDFManual

Get PDF Manual of a Package From CRAN
PlotACF

Combined Plot of a Time Series and Its ACF and PACF
PlotBubble

Draw a Bubble Plot
Outlier

Outlier
PlotArea

Create an Area Plot
PlotBag

Bivariate Boxplot
NALevel

Replace NAs in a Factor by a Given Level
Permn

Number and Samples for Permutations or Combinations of a Set
PairApply

Pairwise Calculations
DescTools Palettes

Some Custom Palettes
Phrase

Phrasing Results of t-Test
PlotCashFlow

Cash Flow Plot
PlotCandlestick

Plot Candlestick Chart
PercTable

Percentage Table
PercentRank

Percent Ranks
PlotConDens

Plot Conditional Densities
PlotFdist

Frequency Distribution Plot
PlotCirc

Plot Circular Plot
PlotECDF

Empirical Cumulative Distribution Function
PlotLinesA

Plot Lines
PlotFun

Plot a Function
PlotFaces

Chernoff Faces
PlotDot

Cleveland's Dot Plots
PlotCorr

Plot a Correlation Matrix
PlotLog

Logarithmic Plot
PlotMiss

Plot Missing Data
PlotMonth

Cycle Plot for Seasonal Effects of an Univariate Time Series
PlotMarDens

Scatterplot With Marginal Densities
PlotMosaic

Mosaic Plots
PlotProbDist

Plot Probability Distribution
PlotPolar

Plot Values on a Circular Grid
PlotPyramid

Draw a Back To Back Pyramid Plot
PlotQQ

QQ-Plot for Any Distribution
PowerPoint Interface

Add Slides, Insert Texts and Plots to PowerPoint
PlotVenn

Plot a Venn Diagram
PostHocTest

Post-Hoc Tests
PolarGrid

Plot a Grid in Polar Coordinates
PlotPairs

Extended Scatterplot Matrices
PlotMultiDens

Plot Multiple Density Curves
Primes

Find All Primes Less Than n
PlotViolin

Plot Violins Instead of Boxplots
PlotTernary

Ternary or Triangular Plots
PoissonCI

Poisson Confidence Interval
PlotTreemap

Create a Treemap
PlotWeb

Plot a Web of Connected Points
Rank

Fast Sample Ranks
Range

(Robust) Range
Recode

Recode a Factor
Quantile

(Weighted) Sample Quantiles
QuantileCI

Confidence Interval for Any Quantile
Rename

Change Names of a Named Object
Recycle

Recyle a List of Elements
Rev

Reverse Elements of a Vector, a Matrix, a Table, an Array or a Data.frame
RelRisk

Relative Risk
PseudoR2

Pseudo R2 Statistics
reorder.factor

Reorder the Levels of a Factor
RevCode

Reverse Codes
RevWeibull

The Reverse Weibull Distribution
ColToOpaque

Equivalent Opaque Color for Transparent Color
RoundTo

Round to Multiple
RomanToInt

Convert Roman Numerals to Integers
RunsTest

Runs Test for Randomness
Quot

Lagged Quotients
Rotate

Rotate a Geometric Structure
PtInPoly

Point in Polygon
RgbToCmy

Conversion Between RGB and CMYK
RgbToCol

Find the Nearest Named R-Color to a Given RGB-Color
RndPairs

Create Pairs of Correlated Random Numbers
RobScale

Robust Scaling With Median and Mad
pRevGumbel

"Reverse" Gumbel Distribution Functions
Depreciation

Several Methods of Depreciation of an Asset
Sample

Random Samples and Permutations
SaveAs

Saves an R Object Under a Different Name
SD

(Weighted) Standard Deviation
SampleTwins

Sample Twins
SignTest

Sign Test
ShapiroFranciaTest

Shapiro-Francia Test for Normality
SiegelTukeyTest

Siegel-Tukey Test For Equality In Variability
SendOutlookMail

Send a Mail Using Outlook as Mail Client
SetNames

Set the Names in an Object
RSessionAlive

How Long Has the RSession Been Running?
SplitToDummy

Split Strings of a Vector and Provide Dummy Codes for Found Pieces
SomersDelta

Somers' Delta
Shade

Produce a Shaded Curve
SplitToCol

Split Data Frame String Column Into Multiple Columns
ScheffeTest

Scheffe Test for Pairwise and Otherwise Comparisons
Measures of Shape

Skewness and Kurtosis
SplitAt

Split a Vector Into Several Pieces at Given Positions
SplitPath

Split Path In Drive, Path, Filename
StrCountW

Count Words in a String
StrDist

Compute Distances Between Strings
SortMixed

Sort Strings with Embedded Numbers Based on Their Numeric Order
SetAlpha

Add an Alpha Channel To a Color
Sort

Sort a Vector, a Matrix, a Table or a Data.frame
SpearmanRho

Spearman Rank Correlation
StrAbbr

String Abbreviation
StrCap

Capitalize the First Letter of a String
StrAlign

String Alignment
StrSpell

Spell a String Using the NATO Phonetic or the Morse Alphabet
StrChop

Split a String into a Number of Sections of Defined Length
StrSplit

Split the Elements of a Character Vector
StrRev

Reverse a String
StdCoef

Standardized Model Coefficients
StrLeft, StrRight

Returns the Left Or the Right Part Of a String
Some

Return Some Randomly Chosen Elements of an Object
SmoothSpline

Formula Interface For smooth.spline
SpreadOut

Spread Out a Vector of Numbers To a Minimum Interval
TMod

Comparison Table For Linear Models
StuartTauC

Stuart \(\tau_{c}\)
StrPad

Pad a String With Justification
TOne

Create Table One Describing Baseline Characteristics
Str

Compactly Display the Structure of any R Object
TTestA

Student's t-Test Based on Sample Statistics
TextContrastColor

Choose Textcolor Depending on Background Color
Stamp

Date/Time/Directory Stamp the Current Plot
StrPos

Find Position of First Occurrence Of a String
TextToTable

Converts String To a Table
SysInfo

System Information
StrExtract

Extract Part of a String
ToWrdPlot

Send a Plot to Word and Bookmark it
TitleRect

Plot Boxed Annotation
StripAttr

Remove Attributes from an Object
StrIsNumeric

Does a String Contain Only Numeric Data
Triangular

The Triangular Distribution
ToLong, ToWide

Reshape a Vector From Long to Wide Shape Or Vice Versa
UncertCoef

Uncertainty Coefficient
UnirootAll

Finds many (all) roots of one equation within an interval
TwoGroups

Describe a Variable by a Factor with Two Levels
StrTrim

Remove Leading/Trailing Whitespace From A String
StrTrunc

Truncate Strings and Add Ellipses If a String is Truncated.
Untable

Recover Original Data From Contingency Table
StuartMaxwellTest

Stuart-Maxwell Marginal Homogeneity Test
WoolfTest

Woolf Test For Homogeneity in 2x2xk Tables
WithOptions

Execute Function with Temporary Options
Strata

Stratified Sampling
StrVal

Extract All Numeric Values From a String
TheilU

Theil's U Index of Inequality
WrdTableBorders

Draw Borders to a Word Table
Trim

Trim a Vector
ToWrd

Send Objects to Word
ToWrdB

Send Objects to Word and Bookmark Them
Unwhich

Inverse Which
VecRot

Vector Rotation (Shift Elements)
VanWaerdenTest

van der Waerden Test
Var

Variance
Vigenere

Vigenere Cypher
WrdPlot

Insert Active Plot to Word
XLDateToPOSIXct

Convert Excel Dates to POSIXct
VIF

Variance Inflation Factors
ZTest

Z Test for Known Population Standard Deviation
WrdBookmark

Some Functions to Handle MS-Word Bookmarks
TukeyBiweight

Calculate Tukey's Biweight Robust Mean
VonNeumannTest

Von Neumann's Successive Difference Test
XLGetRange

Import Data Directly From Excel
VarCI

Confidence Intervals for the Variance
WrdFormatCells

Format Cells Of a Word Table
Winsorize

Winsorize (Replace Extreme Values by Less Extreme Ones)
XLSaveAs

Save Excel File
WrdSaveAs

Open and Save Word Documents
VarTest

ChiSquare Test for One Variance and F Test to Compare Two Variances
WrdCaption

Insert Caption to Word
WrdMergeCells

Merges Cells Of a Defined Word Table Range
%c%

Concatenates Two Strings Without Any Separator
XLView

Use MS-Excel as Viewer for a Data.Frame
power.chisq.test

Power Calculations for ChiSquared Tests
d.countries

ISO 3166-1 Country Codes
WrdCellRange

Return the Cell Range Of a Word Table
WrdStyle

Get or Set the Style in Word
YuenTTest

Yuen t-Test For Trimmed Means
WrdTable

Insert a Table in a Word Document
Zodiac

Calculate the Zodiac of a Date
ZeroIfNA

Replace NAs by 0
d.diamonds

Data diamonds
WrdFont

Get or Set the Font in Word
lines.lm

Add a Linear Regression Line
as.matrix.xtabs

Convert xtabs To matrix
rSum21

Random Numbers Adding Up to 1
lines.loess

Add a Loess or a Spline Smoother
d.whisky

Classification of Scotch Single Malts
identify.formula

Identify Points In a Plot Using a Formula
WrdPageBreak

Insert a Page Break
%like%

Like Operator
matpow

Matrix Power
split.formula

Formula Interface for Split
as.ym

A Class for Dealing with the Yearmonth Format
WrdParagraphFormat

Get or Set the Paragraph Format in Word
axTicks.POSIXct

Compute Axis Tickmark Locations (For POSIXct Axis)
day.name

Build-in Constants Extension
d.periodic

Periodic Table of Elements
d.pizza

Data pizza
%nin%

Find Matching (or Non-Matching) Elements
DescTools Aliases

Some Aliases Set for Convenience
wdConst

Word VBA Constants
%overlaps%

Determines If And How Extensively Two Date Ranges Overlap
AndersonDarlingTest

Anderson-Darling Test of Goodness-of-Fit
ABCCoords

Coordinates for "bottomright", etc.
AllDuplicated

Index Vector of All Values Involved in Ties
AUC

Area Under the Curve
Append

Append Elements to Objects
AddMonths

Add a Month to a Date
Abstract

Display Compact Abstract of a Data Frame
Abind

Combine Multidimensional Arrays
Agree

Raw Simple And Extended Percentage Agreement
AllIdentical

Test Multiple Objects for Exact Equality