Reshaping Data with tidyr
Transform almost any dataset into a tidy format to make analysis easier.
Start Course for Free4 hours15 videos54 exercises17,528 learnersStatement of Accomplishment
Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.Training 2 or more people?
Try DataCamp For BusinessLoved by learners at thousands of companies
Course Description
Data in the wild can be scary—when confronted with a complicated and messy dataset you may find yourself wondering, where do I even start? The tidyr package allows you to wrangle such beasts into nice and tidy datasets. Inaccessible values stored in column names will be put into rows, JSON files will become data frames, and missing values will never go missing again. You'll practice these techniques on a wide range of messy datasets, learning along the way how many dogs the Soviet Union sent into space and what bird is most popular in New Zealand. With the tidyr package in your tidyverse toolkit, you'll be able to transform almost any dataset in a tidy format which will pay-off during the rest of your analysis.
For Business
Training 2 or more people?
Get your team access to the full DataCamp library, with centralized reporting, assignments, projects and moreIn the following Tracks
Data Manipulation in R
Go To TrackImporting & Cleaning Data in R
Go To TrackTidyverse Fundamentals in R
Go To Track- 1
Tidy Data
FreeYou'll be introduced to the concept of tidy data which is central to this course. In the first two lessons, you'll jump straight into the action by separating messy character columns into tidy variables and observations ready for analysis. In the final lesson, you'll learn how to overwrite and remove missing values.
What is tidy data?50 xpTidy data structure100 xpMultiple variables per column100 xpColumns with multiple values50 xpInternational phone numbers100 xpExtracting observations from values100 xpSeparating into columns and rows100 xpMissing values50 xpAnd the Oscar for best director goes to ... <NA>100 xpImputing sales data100 xpNuclear bombs per continent100 xp - 2
From Wide to Long and Back
This chapter is all about pivoting data from a wide to long format and back again using the pivot_longer() and pivot_wider() functions. You'll need these functions when variables are hidden in messy column names or when variables are stored in rows instead of columns. You'll learn about space dogs, nuclear bombs, and planet temperatures along the way.
From wide to long data50 xpNuclear bombs per country100 xpWHO obesity per country100 xpBond... James Bond100 xpDeriving variables from column headers50 xpNew-Zealand's bird of the year100 xpBig tech stock prices100 xpDeriving variables from complex column headers50 xpSoviet space dogs, the dog perspective100 xpWHO obesity vs. life expectancy100 xpUncounting observations100 xpFrom long to wide data50 xpSoviet space dogs, the flight perspective100 xpPlanet temperature & distance to the Sun100 xpTransposing planet data100 xp - 3
Expanding Data
Values can often be missing in your data, and sometimes entire observations are absent too. In this chapter, you'll learn how to complete your dataset with these missing observations. You'll add observations with zero values to counted data, expand time series to a full sequence of intervals, and more!
Creating unique combinations of vectors50 xpLetters of the genetic code100 xpWhen did humans replace dogs in space?100 xpFinding missing observations100 xpCompleting data with all value combinations50 xpCompleting the Solar System100 xpZero Olympic medals100 xpCreating a sequence with full_seq()100 xpThe Cold War's hottest year100 xpAdvanced completions50 xpOlympic medals per continent100 xpTracking a virus outbreak100 xpCounting office occupants100 xp - 4
Rectangling Data
In the final chapter, you'll learn how to turn nested data structures such as JSON and XML files into tidy, rectangular data. This skill will enable you to process data from web APIs. You'll also learn how nested data structures can be used to write elegant modeling pipelines that produce tidy outputs.
Intro to non-rectangular data50 xpRectangular vs. non-rectangular files100 xpRectangling Star Wars movies100 xpFrom nested values to observations50 xpUnnesting wide or long100 xpRectangling Star Wars planets100 xpThe Solar System's biggest moons100 xpSelecting nested variables50 xpHoisting Star Wars films100 xpHoisting movie ratings100 xpNesting data for modeling50 xpTidy model outputs with broom100 xpNesting tibbles100 xpModeling on nested data frames100 xpCongratulations!50 xp
For Business
Training 2 or more people?
Get your team access to the full DataCamp library, with centralized reporting, assignments, projects and moreIn the following Tracks
Data Manipulation in R
Go To TrackImporting & Cleaning Data in R
Go To TrackTidyverse Fundamentals in R
Go To Trackdatasets
Nuclear explosions dataPlanet dataStar Wars dataNetflix dataANSUR II dataOlympic medals datacollaborators
prerequisites
Data Manipulation with dplyrJeroen Boeye
See MoreMachine Learning Engineer @ Faktion
Jeroen is a machine learning engineer working at Faktion, an AI company from Belgium. He uses both R and Python for his analyses and has a PhD background in computational biology. His experience mostly lies in working with structured data, produced by sensors or digital processes.
FAQs
Join over 14 million learners and start Reshaping Data with tidyr today!
Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.