BaşlayınÜcretsiz Başlayın

Setting names

If you have an unnamed list, you can, of course, name each element. This can be very useful for being able to call out certain elements in a list, regardless of their order, especially if you are working with a list that may grow or change over time, or if you use the same code on several different lists. For instance, if you have a list that contains, a data frame, a model, and a plot, being able to call out $plot instead of searching to figure out what numbered element of the plot, is much easier.

Bu egzersiz

Foundations of Functional Programming with purrr

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • With a piped workflow:
    • Name each element of sw_films list and assign to a new list, sw_films_named.
    • Iterate over the title element.
  • Check to make sure the new list has names.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Set names so each element of the list is named for the film title
sw_films_named <- ___ %>% 
  set_names(map_chr(___, "___"))

# Check to see if the names worked/are correct
names(___)
Kodu Düzenle ve Çalıştır