Mapping functions
R has the *apply
family of functions that can take a function and apply it to several or all elements of a list/data.frame/matrix.
The Python equivalent is the built-in map()
function. map()
takes the name of the function as its first argument,
and then a list of values as the second argument.
The specified function is then applied to all the values in the second argument one-at-a-time. Recall that you need to wrap the output of map()
inside list()
to get the desired results.
In the third exercise of this chapter, you used a for
loop to determine the binge status for all the elements in num_drinks
. In this exercise, you will use map()
along with the functions you defined in exercise five to accomplish the same.
Este ejercicio forma parte del curso
Python for R Users
Ejercicio interactivo práctico
Prueba este ejercicio completando el código de muestra.
# map the binge_male function to num_drinks
print(list(map(____, ____)))