tidyr v0.5.1


Monthly downloads



by Hadley Wickham

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.



Build Status codecov.io CRAN_Status_Badge

tidyr is a reframing of reshape2 designed to accompany the tidy data framework, and to work hand-in-hand with magrittr and dplyr to build a solid pipeline for data analysis.

Just as reshape2 did less than reshape, tidyr does less than reshape2. It's designed specifically for tidying data, not the general reshaping that reshape2 does, or the general aggregation that reshape did. In particular, built-in methods only work for data frames, and tidyr provides no margins or aggregation.

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 in to multiple columns, it makes "long" data wider.

These verbs have a number of synonyms:

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

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


tidyr is available from CRAN. Install it with:


The development version can be installed using:

# install.packages("devtools")

Getting started

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

Note that tidyr is designed for use in conjunction with dplyr, so you should always load both:



If you'd like to learn more about these data reshaping operators, I'd recommend the following papers:

Functions in tidyr

Name Description
fill Fill in missing values.
full_seq Create the full sequence of values in a vector.
expand Expand data frame to include all combinations of values
expand_ Expand (standard evaluation).
extract Extract one column into multiple columns.
extract_ Standard-evaluation version of extract.
fill_ Standard-evaluation version of fill.
extract_numeric Extract numeric component of variable.
complete Complete a data frame with missing combinations of data.
complete_ Standard-evaluation version of complete.
nest Nest repeated values in a list-variable.
gather_ Gather (standard-evaluation).
gather Gather columns into key-value pairs.
nest_ Standard-evaluation version of nest.
%>% Pipe operator
separate_rows_ Standard-evaluation version of separate_rows.
population Population data
replace_na Replace missing values
separate_rows Separate a collapsed column into multiple rows.
table1 tabular layouts
separate_ Standard-evaluation version of separate.
unite_ Standard-evaluation version of unite
smiths Some data about the Smith family.
unnest Unnest a list column.
unite Unite multiple columns into one.
spread_ Standard-evaluation version of spread.
unnest_ Standard-evaluation version of unnest.
spread Spread a key-value pair across multiple columns.
separate Separate one column into multiple columns.
who World Health Organization TB data
No Results!

Last month downloads


License MIT + file LICENSE
LazyData true
URL https://github.com/hadley/tidyr
BugReports https://github.com/hadley/tidyr/issues
VignetteBuilder knitr
LinkingTo Rcpp
RoxygenNote 5.0.1
NeedsCompilation yes
Packaged 2016-06-14 12:40:46 UTC; hadley
Repository CRAN
Date/Publication 2016-06-14 15:22:49

Include our badge in your README