Lists Flashcards

1
Q

What does a list do?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the function to create a list?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can you assign names to items in a list after creating it?

A

names()

Ex: names(my_list) <- c(“name1”, “name2”, “name3”, …)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can you select a single component from a list?

A

[[]] OR $

Ex: my_list[[1]] OR my_list[[“diameter”]]

Ex: my_list$diameter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you select a single element from a component of a list?

A

[[]][]

Ex: my_list[[1]][2]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly