Fast Creation of Dummy (Binary) Columns and Rows from Categorical Variables

Creates dummy columns from columns that have categorical variables (character or factor types). You can also specify which columns to make dummies out of, or which columns to ignore. Also creates dummy rows from character, factor, and Date columns. This package provides a significant speed increase from creating dummy variables through model.matrix().

CRAN_Status_Badge AppVeyor Build Status Build Status


The goal of fastDummies is to quickly create dummy variables (columns) and dummy rows. Creating dummy variables is possible through base R or other packages, but this package is much faster than those methods.


To install this package, use the code
# install.packages("devtools")



There are two functions in this package:

  • dummy_cols() lets you make dummy variables (dummy_columns() is a clone of dummy_cols())
  • dummy_rows() which lets you make dummy rows.


fastDummies 1.3.0

  • Adds option to sort dummy columns following the order of the original factor variable. Thanks to Patrick Baylis for the pull request with the code for this feature!

fastDummies 1.2.0

  • Adds option to exclude the most frequently observed category rather than the first category as is default. Thanks to GitHub user S-UP for the suggestion!

fastDummies 1.1.0

  • Thanks to GitHub user yu45020 dummy_cols() is now about >20% faster and much more memory efficient.

  • Both dummy_cols() and dummy_rows() now return the same data type inputted

  • e.g. data.frame input returns data.frame, tibble returns tibble.
  • Fix documentation that incorrectly said default value for new dummy rows is 0. It is in fact a value of NA.

fastDummies 1.0.0

  • Reduces number of parameter that were in previous version.

  • Significant speed increases for both dummy_cols() and dummy_rows() functions.

  • dummy_cols() now accepts numeric columns.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


1.6.3 by Jacob Kaplan, a year ago,

Report a bug at

Browse source code at

Authors: Jacob Kaplan [aut, cre] , Benjamin Schlegel [ctb]

Documentation:   PDF Manual  

MIT + file LICENSE license

Imports data.table, tibble, stringr

Suggests testthat, knitr, rmarkdown, covr, spelling

Imported by BayesianFROC, GenMarkov, MplusAutomation, NeuralSens, bnpa, causalweight, conText, deepdive, drf, framecleaner, gscaLCA, psyntur, tidyvpc.

Suggested by Statsomat, logitr, multifear.

See at CRAN