Multiple variables per column
Being a busy person, you don't want to spend too much time on Netflix, so you decide to crunch some numbers on TV show and movie durations before deciding what to watch.
You've managed to obtain a dataset named netflix_df
, but its duration
column has an issue. It contains strings with both a value and unit of duration ("min"
or "Season"
).
You'll tidy this dataset so that each variable gets its own column.
As will always be the case in this course, the tidyr
package has been pre-loaded for you.
This exercise is part of the course
Reshaping Data with tidyr
Exercise instructions
- Inspect
netflix_df
by typing its name directly in the R console and hitting Enter to see what string separates the value from the unit in theduration
column. - Separate the
duration
column over two variables namedvalue
andunit
. Pass the string separating the number from the unit to thesep
argument.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
netflix_df %>%
# Split the duration column into value and unit columns
separate(___, into = ___, sep = ___, convert = TRUE)