Exercise

map() argument alternatives

You can also use iteration to answer a question, like how long is each element in the wesanderson dataset. You can do this by feeding map() a function like length(). You can do this using the map(list, function) syntax and it works just fine. However, future exercises get more complex, you will need to learn how to do this second way, using:

map(list, ~function(.x))

This second way gives the same result as map(list, function). To specify how the list is used in the function, use the argument .x to denote where the list element goes inside the function. When you want to use .x to show where the element goes in the function, you need to put a ~ in front of the function in the second argument of map().

Instructions 1/2

undefined XP
  • 1

    Use map() on wesanderson and determine the length of each element in the "old" way.

  • 2

    Use map() on wesanderson and determine the length of each element again, but this time using map(list, ~function(.x)).