Skip to content

Pivoting

Pivoting changes the representation of a rectangular dataset, without changing the data inside of it. See vignette("pivot") for more details and examples.

pivot_longer()
Pivot data from wide to long
pivot_wider()
Pivot data from long to wide

Rectangling

Rectangling turns deeply nested lists into tidy tibbles. See vignette("rectangle") for more details and examples.

unnest_longer()
Unnest a list-column into rows
unnest_wider()
Unnest a list-column into columns
unnest()
Unnest a list-column of data frames into rows and columns
hoist()
Hoist values out of list-columns

Character vectors

Multiple variables are sometimes pasted together into a single column, and these tools help you separate back out into individual columns.

separate_longer_delim() separate_longer_position() experimental
Split a string into rows
separate_wider_delim() separate_wider_position() separate_wider_regex() experimental
Split a string into columns
unite()
Unite multiple columns into one by pasting strings together

Missing values

Tools for converting between implicit (absent rows) and explicit (NA) missing values, and for handling explicit NAs.

complete()
Complete a data frame with missing combinations of data
drop_na()
Drop rows containing missing values
expand() crossing() nesting()
Expand data frame to include all possible combinations of values
expand_grid()
Create a tibble from all combinations of inputs
fill()
Fill in missing values with previous or next value
full_seq()
Create the full sequence of values in a vector
replace_na()
Replace NAs with specified values

Miscellanea

chop() unchop()
Chop and unchop
pack() unpack()
Pack and unpack
uncount()
"Uncount" a data frame
nest()
Nest rows into a list-column of data frames

Data

billboard
Song rankings for Billboard top 100 in the year 2000
cms_patient_experience cms_patient_care
Data from the Centers for Medicare & Medicaid Services
construction
Completed construction in the US in 2018
fish_encounters
Fish encounters
household
Household data
relig_income
Pew religion and income survey
smiths
Some data about the Smith family
table1 table2 table3 table4a table4b table5
Example tabular representations
us_rent_income
US rent and income data
who who2 population
World Health Organization TB data
world_bank_pop
Population data from the World Bank

Superseded

Superseded functions have been replaced by superior solutions, but due to their widespread use will not go away. However, they will not get any new features and will only receive critical bug fixes.

extract() superseded
Extract a character column into multiple columns using regular expression groups
separate() superseded
Separate a character column into multiple columns with a regular expression or numeric locations
separate_rows() superseded
Separate a collapsed column into multiple rows
spread() superseded
Spread a key-value pair across multiple columns
gather() superseded
Gather columns into key-value pairs
nest_legacy() unnest_legacy() superseded
Legacy versions of nest() and unnest()