Lists Flashcards
What does a list do?
A list in R allows you to gather a variety of objects under one name (that is, the name of the list) in an ordered way. These objects can be matrices, vectors, data frames, even other lists, etc.
What is the function to create a list?
list()
Ex: list(my_vec1, my_mat, my_vec2, my_df, …) OR list(name1 = my_vec1, name2 = my_mat, name3 = my_vec2, name4 = my_df)
How can you assign names to items in a list after creating it?
names()
Ex: names(my_list) <- c(“name1”, “name2”, “name3”, …)
How can you select a single component from a list?
[[]] OR $
Ex: my_list[[1]] OR my_list[[“diameter”]]
Ex: my_list$diameter
How can you select a single element from a component of a list?
[[]][]
Ex: my_list[[1]][2]