1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Functional Programming with purrr

Exercise

Clean up your data with keep

Since the beginning of this course, we have been using the results of a weeklong A/B test.

We have put these results in a list called all_visits. This list contains visit_a, visit_b, and visit_c. These vectors are unnamed. They all contain seven numbers, one for each day of the week.

The first question we want to ask is: which days reached more than 100 visits an hour on average? We will use the keep() function. But the answer would not be readable with an unnamed vector: you would have the numbers, but you would not know to which day these numbers correspond.

The good news is: you can use the set_names() function to solve this issue. This is what we'll do in this chapter: first, use keep() on unnamed vectors, then on named ones.

Instructions

100 XP
  • Create a mapper that will test if .x is more than 100. You'll use it twice.
  • Combining this mapper with keep(), and map it on the unnamed list all_visit. As the result is unnamed, you don't know which days you have kept.
  • Name each vector by combining map() and the set_names() functions, using the vector of names we have provided.
  • Map the previously created mapper on the newly named list. As you can see, it's more readable now!