Recall & Review
beginner
What is a list in R?
A list in R is a collection that can hold elements of different types, like numbers, strings, or even other lists.
Click to reveal answer
beginner
Why can R lists hold mixed types?
Because lists store elements as separate objects, they don't need all elements to be the same type, unlike vectors.
Click to reveal answer
beginner
How does a list differ from a vector in R regarding types?
Vectors require all elements to be the same type, while lists can hold different types together.
Click to reveal answer
beginner
Give an example of a mixed-type list in R.
list(42, "hello", TRUE) is a list with a number, a string, and a logical value.
Click to reveal answer
beginner
What is a practical reason to use lists with mixed types?
Lists let you group related but different data types, like a person's name (string), age (number), and membership status (logical).Click to reveal answer
What type of elements can an R list contain?
✗ Incorrect
Lists in R can hold elements of different types, unlike vectors which require the same type.
Which R data structure requires all elements to be the same type?
✗ Incorrect
Vectors require all elements to be the same type, while lists do not.
Why are lists useful in R?
✗ Incorrect
Lists can store mixed types, making them flexible for different data.
Which of these is a valid R list?
✗ Incorrect
list(1, "a", TRUE) is a list holding mixed types; c() creates a vector which coerces types.
What happens if you try to mix types in a vector in R?
✗ Incorrect
Vectors coerce all elements to the same type, usually the most flexible type.
Explain why R lists can hold mixed types but vectors cannot.
Think about how elements are stored inside lists versus vectors.
You got /3 concepts.
Describe a real-life example where using a list with mixed types in R is helpful.
Imagine storing a person's name, age, and membership status.
You got /3 concepts.