LoslegenKostenlos loslegen

case_when() with single variable

In this lesson, we saw how we could make a categorical variable from a single vector or column using case_when(). Let's try that out with our dataset, multiple_choice_responses, creating a "generation" variable based on people's reported ages.

We'll use another dplyr function, between, to help us. Combined with filter, between lets us filter for rows that have values between two numbers (inclusive). For example:

mtcars %>%
  filter(between(mpg, 10, 20))

returns all the rows of mtcars where the mpg is between 10 and 20.

Diese Übung ist Teil des Kurses

Categorical Data in the Tidyverse

Kurs anzeigen

Interaktive Übung

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

# Check the min age
___(multiple_choice_responses$Age, ___)

# Check the max age
___(multiple_choice_responses$Age, ___)
Code bearbeiten und ausführen