Recall & Review
beginner
What does the single bracket [ ] operator do when accessing elements in an R list?
The single bracket [ ] returns a sublist containing the selected elements. It preserves the list structure.
Click to reveal answer
beginner
How does the double bracket [[ ]] operator differ from the single bracket [ ] in R?
The double bracket [[ ]] extracts the actual element inside the list, not a sublist. It returns the element itself.
Click to reveal answer
beginner
What is the purpose of the $ operator in R when working with lists or data frames?
The $ operator accesses elements by name directly, returning the element itself, similar to [[ ]] but using the element's name.
Click to reveal answer
intermediate
Given list x <- list(a = 1:3, b = "hello"), what is the result of x["a"]?
It returns a sublist containing the element named 'a', so the output is a list with one element: a = 1:3.
Click to reveal answer
intermediate
Given list x <- list(a = 1:3, b = "hello"), what is the result of x[["a"]]?
It returns the actual element named 'a', which is the vector 1, 2, 3 (not a list).
Click to reveal answer
Which operator returns a sublist when accessing elements in an R list?
✗ Incorrect
The single bracket [ ] returns a sublist, preserving the list structure.
Which operator extracts the actual element from a list in R?
✗ Incorrect
Both [[ ]] and $ extract the actual element, not a sublist.
What does x$element return in R?
✗ Incorrect
The $ operator returns the actual element named 'element' from the list or data frame.
If x is a list, what is the type of x["name"]?
✗ Incorrect
Using single brackets with a name returns a sublist containing that element.
Which operator can you use to access a list element by name without quotes?
✗ Incorrect
The $ operator accesses elements by name without needing quotes.
Explain the difference between [ ], [[ ]], and $ when accessing elements in an R list.
Think about whether you want a list or the element itself.
You got /4 concepts.
Describe a situation where using [ ] instead of [[ ]] would cause unexpected results in R.
Consider what happens if you try to use a vector function on a sublist.
You got /3 concepts.