Exercise

The ... argument to the map functions

The map functions use the ... ("dot dot dot") argument to pass along additional arguments to .f each time it’s called. For example, we can pass the trim argument to the mean() function:

map_dbl(df, mean, trim = 0.5)

Multiple arguments can be passed along using commas to separate them. For example, we can also pass the na.rm argument to mean():

map_dbl(df, mean, trim = 0.5, na.rm = TRUE)

You don't have to specify the arguments by name, but it is good practice!

You may be wondering why the arguments to map() are .x and .f and not x and f? It's because .x and .f are very unlikely to be argument names you might pass through the ..., thereby preventing confusion about whether an argument belongs to map() or to the function being mapped.

Let's get a bit of practice with this. We'll apply our new knowledge to a subset of the planes data frame available in the nycflights13 package. Use map_dbl() to find the average and 5th percentile of each column in planes.

Instructions

100xp

Find the column means of planes by combining map_dbl() with mean().

Find the column means of planes again, but this time exclude missing values from the calculation.

Find the 5th percentile of each column in planes by combining map_dbl with quantile(). Don't forget to exclude missing values!