Lambda functions
We are still working with the results of a weeklong A/B test on a website. The three vectors containing the number of visits for each design (visit_a, visit_b and visit_c) are available in your workspace.
One of your colleagues has asked you to transfer him the results, but he wants them to be rounded to the nearest ten. To do this, you will need to call the round() function this way:
Rounding to a negative number of digits means rounding to a power of ten, so for example round(x, digits = -2) rounds to the nearest hundred
Definition taken from R documentation: see ?round
Make sure to use the right map_* for each call.
Este exercício faz parte do curso
Intermediate Functional Programming with purrr
Instruções do exercício
- Round
visit_ato the nearest ten with a mapper. - Create a reusable mapper object called
to_ten, that rounds to the nearest ten. - Map
to_tentovisit_b. - Map
to_tentovisit_c.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Round visit_a to the nearest tenth with a mapper
___(visit_a, ~ ___(.x, -1))
# Create to_ten, a mapper that rounds to the nearest tenth
to_ten <- ___(~ ___(.x, ___))
# Map to_ten on visit_b
___(visit_b, ___)
# Map to_ten on visit_c
___(visit_c, ___)