Refreshing your purrr memory

Let's pretend you're a data analyst working for a web agency. The web-design team has been running a weeklong A/B test that compares the performance of two design proposals for a website, and you're now in charge of analyzing the results.

The team measured the number of visits to the Contact page to determine the design's impact on the number of people contacting the company. These designs were presented to 2/3 of visitors.

visit_a contains the results from campaign A and visit_b the results of campaign B. Both are expressed as an average hourly number of visits. All the other stats you have are expressed as visits per day, so you need to convert these two. Then, you'll extract the mean of each vector.

Note that these are new data, not the one from the video.

This exercise is part of the course

Intermediate Functional Programming with purrr

View Course

Exercise instructions

  • Create the to_day() function, which multiplies x by 24.
  • Create a list that contains visit_a and visit_b.
  • Turn your new list to the daily number of visits with map() and the to_day() function.
  • Compare the mean of visits by mapping the mean() function on the results.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create the to_day function
to_day <- function(x) {
 ___
}

# Create a list containing both vectors: all_visits
all_visits <- list(___, ___)

# Convert to daily number of visits: all_visits_day
all_visits_day <- map(___, ___)

# Map the mean() function and output a numeric vector 
___(all_visits_day, ___)