tidyr v0.8.3


Monthly downloads



Easily Tidy Data with 'spread()' and 'gather()' Functions

An evolution of 'reshape2'. It's designed specifically for data tidying (not general reshaping or aggregating) and works well with 'dplyr' data pipelines.



status Travis build
status Codecov test


The goal of tidyr is to help you create tidy data. Tidy data is data where:

  1. Each variable is in a column.
  2. Each observation is a row.
  3. Each value is a cell.

Tidy data describes a standard way of storing data that is used wherever possible throughout the tidyverse. If you ensure that your data is tidy, you’ll spend less time fighting with the tools and more time working on your analysis.


# The easiest way to get tidyr is to install the whole tidyverse:

# Alternatively, install just tidyr:

# Or the development version from GitHub:
# install.packages("devtools")


Getting started


There are two fundamental verbs of data tidying:

  • gather() takes multiple columns, and gathers them into key-value pairs: it makes “wide” data longer.

  • spread() takes two columns (key & value), and spreads into multiple columns: it makes “long” data wider.

tidyr also provides separate() and extract() functions which makes it easier to pull apart a column that represents multiple variables. The complement to separate() is unite().

To get started, read the tidy data vignette (vignette("tidy-data")) and check out the demos (demo(package = "tidyr")).

tidyr replaces reshape2 (2010-2014) and reshape (2005-2010). Somewhat counterintuitively each iteration of the package has done less. tidyr is designed specifically for tidying data, not general reshaping (reshape2), or the general aggregation (reshape).

If you’d like to read more about data reshaping from a CS perspective, I’d recommend the following three papers:

To guide your reading, here’s a translation between the terminology used in different places:

tidyr gather spread
reshape(2) melt cast
spreadsheets unpivot pivot
databases fold unfold

Getting help

If you encounter a clear bug, please file a minimal reproducible example on github. For questions and other discussion, please use community.rstudio.com.

Please note that the tidyr project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Functions in tidyr

Name Description
fill Fill in missing values.
full_seq Create the full sequence of values in a vector.
separate Separate one column into multiple columns.
separate_rows Separate a collapsed column into multiple rows.
gather Gather columns into key-value pairs.
spread Spread a key-value pair across multiple columns.
extract Extract one column into multiple columns.
complete Complete a data frame with missing combinations of data.
extract_numeric Extract numeric component of variable.
nest Nest repeated values in a list-variable.
uncount "Uncount" a data frame
table1 Example tabular representations
unite Unite multiple columns into one.
unnest Unnest a list column.
who World Health Organization TB data
tidyr-package tidyr: Easily Tidy Data with 'spread()' and 'gather()' Functions
deprecated-se Deprecated SE versions of main verbs
%>% Pipe operator
replace_na Replace missing values
drop_na Drop rows containing missing values
expand Expand data frame to include all combinations of values
smiths Some data about the Smith family.
No Results!

Vignettes of tidyr

No Results!

Last month downloads


License MIT + file LICENSE
URL http://tidyr.tidyverse.org, https://github.com/tidyverse/tidyr
BugReports https://github.com/tidyverse/tidyr/issues
LinkingTo Rcpp
VignetteBuilder knitr
Encoding UTF-8
LazyData true
RoxygenNote 6.1.1
NeedsCompilation yes
Packaged 2019-02-28 16:04:27 UTC; hadley
Repository CRAN
Date/Publication 2019-03-01 23:00:03 UTC

Include our badge in your README