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

Named lists

Knowing how forgetful you are, you decide it would be important to add names to your list so you can remember what each element is describing. There are two ways to do this!

You could name the elements as you create the list with the form name = value:

my_list <- list(my_words = words, my_numbers = numbers)

Or, if the list was already created, you could use names():

my_list <- list(words, numbers)
names(my_list) <- c("my_words", "my_numbers") 

Both would result in:

my_list

$my_words
[1] "I <3 R"

$my_numbers
[1] 42 24

Bu egzersiz

Introduction to R for Finance

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

Egzersiz talimatları

  • The portfolio list is available to work with.
  • Use names() to add the following names to your list: "portfolio_name", "apple", "ibm", "correlation", in that order.
  • Print portfolio to see your newly named list.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Add names to your portfolio


# Print portfolio
Kodu Düzenle ve Çalıştır