Skip to content
Course Notes: Introduction to R
  • AI Chat
  • Code
  • Report
  • Write and run code here

    Creating a named list Well done, you're on a roll!

    Just like on your to-do list, you want to avoid not knowing or remembering what the components of your list stand for. That is why you should give names to them:

    my_list <- list(name1 = your_comp1, name2 = your_comp2) This creates a list with components that are named name1, name2, and so on. If you want to name your lists after you've created them, you can use the names() function as you did with vectors. The following commands are fully equivalent to the assignment above:

    my_list <- list(your_comp1, your_comp2) names(my_list) <- c("name1", "name2")