fastDummies
The goal of fastDummies is to quickly create dummy variables (columns) and dummy rows.
Science Score: 10.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
○codemeta.json file
-
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
1 of 5 committers (20.0%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (15.4%) to scientific vocabulary
Keywords
binary-data
dummy-columns
dummy-data
dummy-rows
dummy-variable
Last synced: 6 months ago
·
JSON representation
Repository
The goal of fastDummies is to quickly create dummy variables (columns) and dummy rows.
Basic Info
- Host: GitHub
- Owner: jacobkap
- License: other
- Language: R
- Default Branch: master
- Homepage: https://jacobkap.github.io/fastDummies/
- Size: 45.7 MB
Statistics
- Stars: 39
- Watchers: 3
- Forks: 9
- Open Issues: 2
- Releases: 0
Topics
binary-data
dummy-columns
dummy-data
dummy-rows
dummy-variable
Created almost 9 years ago
· Last pushed about 1 year ago
Metadata Files
Readme
License
README.Rmd
---
output: github_document
---
[](https://cran.r-project.org/package=fastDummies)
[](https://ci.appveyor.com/project/jacobkap/fastDummies)
[](https://app.travis-ci.com/jacobkap/fastDummies)
[](https://app.codecov.io/github/jacobkap/fastDummies?branch=master)
[](https://cran.r-project.org/package=fastDummies)
## Overview
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.
## Installation
```{r, eval = FALSE}
To install this package, use the code
install.packages("fastDummies")
# The development version is available on Github.
# install.packages("devtools")
devtools::install_github("jacobkap/fastDummies")
```
## Usage
```{r}
library(fastDummies)
```
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.
# Dummy Columns
Dummy variables (or binary variables) are commonly used in statistical analyses and in more simple descriptive statistics. A dummy column is one which has a value of one when a categorical event occurs and a zero when it doesn't occur. In most cases this is a feature of the event/person/object being described. For example, if the dummy variable was for occupation being an R programmer, you can ask, "is this person an R programmer?" When the answer is yes, they get a value of 1, when it is no, they get a value of 0.
We'll start with a simple example and then go into using the function `dummy_cols()`. You can also use the function `dummy_columns()` which is identical to `dummy_cols()`.
Imagine you have a data set about animals in a local shelter. One of the columns in your data is what animal it is: dog or cat.
```{r echo=FALSE}
knitr::kable(data.frame(animals = c("dog", "dog", "cat")))
```
To make dummy columns from this data, you would need to produce two new columns. One would indicate if the animal is a dog, and the other would indicate if the animal is a cat. Each row would get a value of 1 in the column indicating which animal they are, and 0 in the other column.
animals | dog | cat
--- | --- | ---
dog | 1 | 0
dog | 1 | 0
cat | 0 | 1
In the function dummy_cols, the names of these new columns are concatenated to the original column and separated by an underscore.
animals | animals_dog | animals_cat
--- | --- | ---
dog | 1 | 0
dog | 1 | 0
cat | 0 | 1
With an example like this, it is fairly easy to make the dummy columns yourself. `dummy_cols()` automates the process, and is useful when you have many columns to general dummy variables from or with many categories within the column.
```{r setup, echo=TRUE}
fastDummies_example <- data.frame(numbers = 1:3,
gender = c("male", "male", "female"),
animals = c("dog", "dog", "cat"),
dates = as.Date(c("2012-01-01", "2011-12-31",
"2012-01-01")),
stringsAsFactors = FALSE)
knitr::kable(fastDummies_example)
```
The object **fastDummies_example** has two character type columns, one integer column, and a Date column. By default, `dummy_cols()` will make dummy variables from factor or character columns only. This is because in most cases those are the only types of data you want dummy variables from. If those are the only columns you want, then the function takes your data set as the first parameter and returns a data.frame with the newly created variables appended to the end of the original data.
```{r echo=TRUE}
results <- fastDummies::dummy_cols(fastDummies_example)
knitr::kable(results)
```
# Dummy Rows
When dealing with data, there are often missing rows. While truly handling missing data is far beyond the scope of this package, the function `dummy_rows()` lets you add those missing rows back into the data.
The function takes all character, factor, and Date columns, finds all possible combinations of their values, and adds the rows that are not in the original data set. Any columns not used in creating the combinations (e.g. numeric) are given a value of NA (unless otherwise specified with *dummy_value*).
Lets start with a simple example.
```{r echo=TRUE}
fastDummies_example <- data.frame(numbers = 1:3,
gender = c("male", "male", "female"),
animals = c("dog", "dog", "cat"),
dates = as.Date(c("2012-01-01", "2011-12-31",
"2012-01-01")),
stringsAsFactors = FALSE)
knitr::kable(fastDummies_example)
```
This data set has four columns: two character, one Date, and one numeric. The function by default will use the character and Date columns in creating the combinations. First, a small amount of math to explain the combinations. Each column has two distinct values - gender: male & female; animals: dog & cat; dates: 2011-12-31 & 2011-12-31. To find the number of possible combinations, multiple the number of unique values in each column together. 2 \* 2 \* 2 = 8.
```{r echo=TRUE}
results <- fastDummies::dummy_rows(fastDummies_example)
knitr::kable(results)
```
Owner
- Name: Jacob Kaplan
- Login: jacobkap
- Kind: user
- Website: http://jacobdkaplan.com/
- Repositories: 8
- Profile: https://github.com/jacobkap
GitHub Events
Total
- Issues event: 6
- Watch event: 3
- Issue comment event: 3
- Push event: 5
Last Year
- Issues event: 6
- Watch event: 3
- Issue comment event: 3
- Push event: 5
Committers
Last synced: over 2 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| jacobkap | j****p@s****u | 39 |
| Jacob Kaplan | j****6@g****m | 39 |
| Your name | e****s@g****m | 8 |
| Patrick Baylis | p****s@g****m | 1 |
| teofiln | t****n@g****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 28
- Total pull requests: 5
- Average time to close issues: 3 months
- Average time to close pull requests: 14 days
- Total issue authors: 25
- Total pull request authors: 3
- Average comments per issue: 1.11
- Average comments per pull request: 1.8
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 2
- Pull requests: 0
- Average time to close issues: 17 days
- Average time to close pull requests: N/A
- Issue authors: 2
- Pull request authors: 0
- Average comments per issue: 1.0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- ChandlerLutz (3)
- mattsigal (2)
- dwwolfson (1)
- pbaylis (1)
- mysakbm (1)
- annacheyette (1)
- njudd (1)
- ArmandoRl1 (1)
- jhelvy (1)
- benjaminschlegel (1)
- S-UP (1)
- eden70 (1)
- ghost (1)
- ANDEF89 (1)
- burningdrop (1)
Pull Request Authors
- yu45020 (3)
- pbaylis (1)
- teofiln (1)
Top Labels
Issue Labels
bug (6)
feature (2)
enhancement (1)
Pull Request Labels
Packages
- Total packages: 2
-
Total downloads:
- cran 44,456 last-month
- Total docker downloads: 50,925
-
Total dependent packages: 34
(may contain duplicates) -
Total dependent repositories: 43
(may contain duplicates) - Total versions: 23
- Total maintainers: 1
cran.r-project.org: fastDummies
Fast Creation of Dummy (Binary) Columns and Rows from Categorical Variables
- Homepage: https://github.com/jacobkap/fastDummies
- Documentation: http://cran.r-project.org/web/packages/fastDummies/fastDummies.pdf
- License: MIT + file LICENSE
-
Latest release: 1.7.5
published about 1 year ago
Rankings
Downloads: 1.9%
Dependent packages count: 2.4%
Dependent repos count: 4.0%
Forks count: 7.3%
Average: 7.4%
Stargazers count: 8.6%
Docker downloads count: 20.2%
Maintainers (1)
Last synced:
6 months ago
conda-forge.org: r-fastdummies
- Homepage: https://github.com/jacobkap/fastDummies
- License: MIT
-
Latest release: 1.6.3
published about 5 years ago
Rankings
Dependent repos count: 24.3%
Dependent packages count: 29.0%
Average: 35.9%
Stargazers count: 44.1%
Forks count: 46.2%
Last synced:
7 months ago
Dependencies
DESCRIPTION
cran
- R >= 2.10 depends
- data.table * imports
- stringr * imports
- tibble * imports
- covr * suggests
- knitr * suggests
- rmarkdown * suggests
- spelling * suggests
- testthat >= 2.1.0 suggests
revdep/library/fastDummies/new/assertthat/DESCRIPTION
cran
- tools * imports
- covr * suggests
- testthat * suggests
revdep/library/fastDummies/new/cli/DESCRIPTION
cran
- R >= 2.10 depends
- assertthat * imports
- crayon >= 1.3.4 imports
- fansi * imports
- glue * imports
- methods * imports
- utils * imports
- callr * suggests
- covr * suggests
- htmlwidgets * suggests
- knitr * suggests
- mockery * suggests
- prettycode >= 1.1.0 suggests
- ps >= 1.3.4.9000 suggests
- rmarkdown * suggests
- rstudioapi * suggests
- testthat * suggests
- withr * suggests
revdep/library/fastDummies/new/crayon/DESCRIPTION
cran
- grDevices * imports
- methods * imports
- utils * imports
- mockery * suggests
- rstudioapi * suggests
- testthat * suggests
- withr * suggests
revdep/library/fastDummies/new/data.table/DESCRIPTION
cran
- R >= 3.1.0 depends
- methods * imports
- R.utils * suggests
- bit64 * suggests
- curl * suggests
- knitr * suggests
- nanotime * suggests
- rmarkdown * suggests
- xts * suggests
- yaml * suggests
- zoo * suggests
revdep/library/fastDummies/new/digest/DESCRIPTION
cran
- R >= 3.3.0 depends
- utils * imports
- knitr * suggests
- minidown * suggests
- rmarkdown * suggests
- tinytest * suggests
revdep/library/fastDummies/new/ellipsis/DESCRIPTION
cran
- R >= 3.2 depends
- rlang >= 0.3.0 imports
- covr * suggests
- testthat * suggests
revdep/library/fastDummies/new/fansi/DESCRIPTION
cran
- R >= 3.1.0 depends
- knitr * suggests
- rmarkdown * suggests
- unitizer * suggests
revdep/library/fastDummies/new/fastDummies/DESCRIPTION
cran
- R >= 2.10 depends
- data.table * imports
- stringr * imports
- tibble * imports
- covr * suggests
- knitr * suggests
- rmarkdown * suggests
- spelling * suggests
- testthat >= 2.1.0 suggests
revdep/library/fastDummies/new/glue/DESCRIPTION
cran
- R >= 3.2 depends
- methods * imports
- DBI * suggests
- R.utils * suggests
- RSQLite * suggests
- covr * suggests
- crayon * suggests
- dplyr * suggests
- forcats * suggests
- ggplot2 * suggests
- knitr * suggests
- magrittr * suggests
- microbenchmark * suggests
- rmarkdown * suggests
- rprintf * suggests
- stringr * suggests
- testthat * suggests
- vctrs >= 0.3.0 suggests
- withr * suggests
revdep/library/fastDummies/new/lifecycle/DESCRIPTION
cran
- R >= 3.2 depends
- glue * imports
- rlang >= 0.4.0 imports
- covr * suggests
- crayon * suggests
- knitr * suggests
- rmarkdown * suggests
- testthat >= 2.1.0 suggests
revdep/library/fastDummies/new/magrittr/DESCRIPTION
cran
- covr * suggests
- knitr * suggests
- rlang * suggests
- rmarkdown * suggests
- testthat * suggests
revdep/library/fastDummies/new/pillar/DESCRIPTION
cran
- cli * imports
- crayon >= 1.3.4 imports
- ellipsis * imports
- fansi * imports
- lifecycle * imports
- rlang >=0.3.0 imports
- utf8 >= 1.1.0 imports
- vctrs >= 0.2.0 imports
- bit64 * suggests
- knitr * suggests
- lubridate * suggests
- testthat >= 2.0.0 suggests
- withr * suggests
revdep/library/fastDummies/new/pkgconfig/DESCRIPTION
cran
- utils * imports
- covr * suggests
- disposables >= 1.0.3 suggests
- testthat * suggests
revdep/library/fastDummies/new/rlang/DESCRIPTION
cran
- R >= 3.3.0 depends
- winch * enhances
- cli * suggests
- covr * suggests
- crayon * suggests
- glue * suggests
- magrittr * suggests
- methods * suggests
- pillar * suggests
- rmarkdown * suggests
- testthat >= 2.3.0 suggests
- vctrs >= 0.2.3 suggests
- withr * suggests
revdep/library/fastDummies/new/stringi/DESCRIPTION
cran
- R >= 2.14 depends
- stats * imports
- tools * imports
- utils * imports
revdep/library/fastDummies/new/stringr/DESCRIPTION
cran
- R >= 3.1 depends
- glue >= 1.2.0 imports
- magrittr * imports
- stringi >= 1.1.7 imports
- covr * suggests
- htmltools * suggests
- htmlwidgets * suggests
- knitr * suggests
- rmarkdown * suggests
- testthat * suggests
revdep/library/fastDummies/new/tibble/DESCRIPTION
cran
- R >= 3.1.0 depends
- cli * imports
- crayon >= 1.3.4 imports
- ellipsis >= 0.2.0 imports
- fansi >= 0.4.0 imports
- lifecycle >= 0.2.0 imports
- magrittr * imports
- methods * imports
- pillar >= 1.4.3 imports
- pkgconfig * imports
- rlang >= 0.4.3 imports
- utils * imports
- vctrs >= 0.3.2 imports
- bench * suggests
- bit64 * suggests
- blob * suggests
- covr * suggests
- dplyr * suggests
- evaluate * suggests
- formattable * suggests
- hms * suggests
- htmltools * suggests
- import * suggests
- knitr * suggests
- lubridate * suggests
- mockr * suggests
- nycflights13 * suggests
- purrr * suggests
- rmarkdown * suggests
- testthat >= 2.1.0 suggests
- tidyr * suggests
- withr * suggests
revdep/library/fastDummies/new/utf8/DESCRIPTION
cran
- R >= 2.10 depends
- knitr * suggests
- rmarkdown * suggests
- testthat * suggests
revdep/library/fastDummies/new/vctrs/DESCRIPTION
cran
- R >= 3.3 depends
- digest * imports
- ellipsis >= 0.2.0 imports
- glue * imports
- rlang >= 0.4.7 imports
- bit64 * suggests
- covr * suggests
- crayon * suggests
- dplyr >= 0.8.5 suggests
- generics * suggests
- knitr * suggests
- pillar >= 1.4.4 suggests
- pkgdown * suggests
- rmarkdown * suggests
- testthat >= 2.3.0 suggests
- tibble * suggests
- waldo >= 0.2.0 suggests
- withr * suggests
- xml2 * suggests
- zeallot * suggests
revdep/library/fastDummies/old/assertthat/DESCRIPTION
cran
- tools * imports
- covr * suggests
- testthat * suggests
revdep/library/fastDummies/old/cli/DESCRIPTION
cran
- R >= 2.10 depends
- assertthat * imports
- crayon >= 1.3.4 imports
- fansi * imports
- glue * imports
- methods * imports
- utils * imports
- callr * suggests
- covr * suggests
- htmlwidgets * suggests
- knitr * suggests
- mockery * suggests
- prettycode >= 1.1.0 suggests
- ps >= 1.3.4.9000 suggests
- rmarkdown * suggests
- rstudioapi * suggests
- testthat * suggests
- withr * suggests
revdep/library/fastDummies/old/crayon/DESCRIPTION
cran
- grDevices * imports
- methods * imports
- utils * imports
- mockery * suggests
- rstudioapi * suggests
- testthat * suggests
- withr * suggests
revdep/library/fastDummies/old/data.table/DESCRIPTION
cran
- R >= 3.1.0 depends
- methods * imports
- R.utils * suggests
- bit64 * suggests
- curl * suggests
- knitr * suggests
- nanotime * suggests
- rmarkdown * suggests
- xts * suggests
- yaml * suggests
- zoo * suggests
revdep/library/fastDummies/old/digest/DESCRIPTION
cran
- R >= 3.3.0 depends
- utils * imports
- knitr * suggests
- minidown * suggests
- rmarkdown * suggests
- tinytest * suggests
revdep/library/fastDummies/old/ellipsis/DESCRIPTION
cran
- R >= 3.2 depends
- rlang >= 0.3.0 imports
- covr * suggests
- testthat * suggests
revdep/library/fastDummies/old/fansi/DESCRIPTION
cran
- R >= 3.1.0 depends
- knitr * suggests
- rmarkdown * suggests
- unitizer * suggests
revdep/library/fastDummies/old/fastDummies/DESCRIPTION
cran
- R >= 2.10 depends
- data.table * imports
- stringr * imports
- tibble * imports
- covr * suggests
- knitr * suggests
- rmarkdown * suggests
- spelling * suggests
- testthat >= 2.1.0 suggests
revdep/library/fastDummies/old/glue/DESCRIPTION
cran
- R >= 3.2 depends
- methods * imports
- DBI * suggests
- R.utils * suggests
- RSQLite * suggests
- covr * suggests
- crayon * suggests
- dplyr * suggests
- forcats * suggests
- ggplot2 * suggests
- knitr * suggests
- magrittr * suggests
- microbenchmark * suggests
- rmarkdown * suggests
- rprintf * suggests
- stringr * suggests
- testthat * suggests
- vctrs >= 0.3.0 suggests
- withr * suggests
revdep/library/fastDummies/old/lifecycle/DESCRIPTION
cran
- R >= 3.2 depends
- glue * imports
- rlang >= 0.4.0 imports
- covr * suggests
- crayon * suggests
- knitr * suggests
- rmarkdown * suggests
- testthat >= 2.1.0 suggests
revdep/library/fastDummies/old/magrittr/DESCRIPTION
cran
- covr * suggests
- knitr * suggests
- rlang * suggests
- rmarkdown * suggests
- testthat * suggests
revdep/library/fastDummies/old/pillar/DESCRIPTION
cran
- cli * imports
- crayon >= 1.3.4 imports
- ellipsis * imports
- fansi * imports
- lifecycle * imports
- rlang >=0.3.0 imports
- utf8 >= 1.1.0 imports
- vctrs >= 0.2.0 imports
- bit64 * suggests
- knitr * suggests
- lubridate * suggests
- testthat >= 2.0.0 suggests
- withr * suggests
revdep/library/fastDummies/old/pkgconfig/DESCRIPTION
cran
- utils * imports
- covr * suggests
- disposables >= 1.0.3 suggests
- testthat * suggests
revdep/library/fastDummies/old/rlang/DESCRIPTION
cran
- R >= 3.3.0 depends
- winch * enhances
- cli * suggests
- covr * suggests
- crayon * suggests
- glue * suggests
- magrittr * suggests
- methods * suggests
- pillar * suggests
- rmarkdown * suggests
- testthat >= 2.3.0 suggests
- vctrs >= 0.2.3 suggests
- withr * suggests
revdep/library/fastDummies/old/stringi/DESCRIPTION
cran
- R >= 2.14 depends
- stats * imports
- tools * imports
- utils * imports
revdep/library/fastDummies/old/stringr/DESCRIPTION
cran
- R >= 3.1 depends
- glue >= 1.2.0 imports
- magrittr * imports
- stringi >= 1.1.7 imports
- covr * suggests
- htmltools * suggests
- htmlwidgets * suggests
- knitr * suggests
- rmarkdown * suggests
- testthat * suggests
revdep/library/fastDummies/old/tibble/DESCRIPTION
cran
- R >= 3.1.0 depends
- cli * imports
- crayon >= 1.3.4 imports
- ellipsis >= 0.2.0 imports
- fansi >= 0.4.0 imports
- lifecycle >= 0.2.0 imports
- magrittr * imports
- methods * imports
- pillar >= 1.4.3 imports
- pkgconfig * imports
- rlang >= 0.4.3 imports
- utils * imports
- vctrs >= 0.3.2 imports
- bench * suggests
- bit64 * suggests
- blob * suggests
- covr * suggests
- dplyr * suggests
- evaluate * suggests
- formattable * suggests
- hms * suggests
- htmltools * suggests
- import * suggests
- knitr * suggests
- lubridate * suggests
- mockr * suggests
- nycflights13 * suggests
- purrr * suggests
- rmarkdown * suggests
- testthat >= 2.1.0 suggests
- tidyr * suggests
- withr * suggests
revdep/library/fastDummies/old/utf8/DESCRIPTION
cran
- R >= 2.10 depends
- knitr * suggests
- rmarkdown * suggests
- testthat * suggests
revdep/library/fastDummies/old/vctrs/DESCRIPTION
cran
- R >= 3.3 depends
- digest * imports
- ellipsis >= 0.2.0 imports
- glue * imports
- rlang >= 0.4.7 imports
- bit64 * suggests
- covr * suggests
- crayon * suggests
- dplyr >= 0.8.5 suggests
- generics * suggests
- knitr * suggests
- pillar >= 1.4.4 suggests
- pkgdown * suggests
- rmarkdown * suggests
- testthat >= 2.3.0 suggests
- tibble * suggests
- waldo >= 0.2.0 suggests
- withr * suggests
- xml2 * suggests
- zeallot * suggests