Challenge - 5 Problems
R List Access Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of list element access with single brackets
What is the output of this R code?
my_list <- list(a = 1:3, b = 4:6) result <- my_list["a"] print(result)
R Programming
my_list <- list(a = 1:3, b = 4:6) result <- my_list["a"] print(result)
Attempts:
2 left
💡 Hint
Remember that single brackets return a sublist, not the element itself.
✗ Incorrect
Using single brackets ["a"] on a list returns a sublist containing the element named 'a'. It keeps the list structure.
❓ Predict Output
intermediate2:00remaining
Output of list element access with double brackets
What is the output of this R code?
my_list <- list(a = 1:3, b = 4:6) result <- my_list[["a"]] print(result)
R Programming
my_list <- list(a = 1:3, b = 4:6) result <- my_list[["a"]] print(result)
Attempts:
2 left
💡 Hint
Double brackets extract the element itself, not a sublist.
✗ Incorrect
Using double brackets [["a"]] extracts the element named 'a' from the list, returning the vector 1 2 3 directly.
❓ Predict Output
advanced2:00remaining
Accessing data frame columns with $ operator
What is the output of this R code?
df <- data.frame(x = 1:3, y = 4:6) result <- df$y print(result)
R Programming
df <- data.frame(x = 1:3, y = 4:6) result <- df$y print(result)
Attempts:
2 left
💡 Hint
The $ operator extracts a column as a vector.
✗ Incorrect
Using df$y extracts the column 'y' from the data frame as a vector 4 5 6.
❓ Predict Output
advanced2:00remaining
Difference between single and double brackets on nested list
What is the output of this R code?
nested_list <- list(a = list(b = 10)) result1 <- nested_list["a"] result2 <- nested_list[["a"]] print(result1) print(result2)
R Programming
nested_list <- list(a = list(b = 10)) result1 <- nested_list["a"] result2 <- nested_list[["a"]] print(result1) print(result2)
Attempts:
2 left
💡 Hint
Single brackets keep the outer list structure; double brackets extract the inner element.
✗ Incorrect
result1 keeps the outer list with element 'a' which itself is a list; result2 extracts the inner list directly.
🧠 Conceptual
expert3:00remaining
Why does my_list$a and my_list[["a"]] differ from my_list["a"]?
Consider this R list:
Which statement best explains the difference between
my_list <- list(a = 1:3, b = 4:6)
Which statement best explains the difference between
my_list$a, my_list[["a"]], and my_list["a"]?Attempts:
2 left
💡 Hint
Think about how $ and [[ ]] extract elements versus [ ] returning sublists.
✗ Incorrect
The $ operator and double brackets [[ ]] extract the element itself, while single brackets [ ] return a sublist preserving the list structure.