LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Reshaping Data with tidyr

Kurs anzeigen

Anleitung zur Übung

  • 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 the duration column.
  • Separate the duration column over two variables named value and unit. Pass the string separating the number from the unit to the sep argument.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

netflix_df %>% 
  # Split the duration column into value and unit columns
  separate(___, into = ___, sep = ___, convert = TRUE)
Code bearbeiten und ausführen