0
0
R Programmingprogramming~20 mins

Nested lists in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nested List Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of nested list indexing
What is the output of the following R code?
R Programming
nested_list <- list(a = list(1, 2, 3), b = list(4, 5, 6))
result <- nested_list$a[[2]]
print(result)
A[1] 3
B[1] 2
C[1] 1
DNULL
Attempts:
2 left
💡 Hint
Remember that [[ ]] extracts the element itself, not a sublist.
Predict Output
intermediate
2:00remaining
Length of nested list element
What is the value of length(nested_list$b) after running this code?
R Programming
nested_list <- list(a = list(1, 2, 3), b = list(4, 5, 6))
length(nested_list$b)
A3
B1
C6
DNULL
Attempts:
2 left
💡 Hint
length() returns the number of elements in the list, not the sum of elements.
Predict Output
advanced
2:00remaining
Output of nested list modification
What is the output of this R code?
R Programming
nested_list <- list(a = list(1, 2), b = list(3, 4))
nested_list$a[[2]] <- 10
print(nested_list$a)
AError: object of type 'closure' is not subsettable
B
[[1]] 1
[[2]] 2
C[1] 1 10
D
[[1]] 1
[[2]] 10
Attempts:
2 left
💡 Hint
Using [[ ]] allows you to replace the element inside the nested list.
Predict Output
advanced
2:00remaining
Accessing deeply nested list element
What is the output of this code?
R Programming
nested_list <- list(x = list(y = list(z = 42)))
print(nested_list$x$y$z)
A[1] 42
BNULL
CError: object 'z' not found
D[1] "42"
Attempts:
2 left
💡 Hint
Use $ to access named elements inside nested lists.
🧠 Conceptual
expert
2:00remaining
Number of elements in a nested list
Given the nested list below, how many top-level elements does it have?
R Programming
nested_list <- list(alpha = list(1, 2), beta = list(3, 4), gamma = 5)
A5
B2
C3
D1
Attempts:
2 left
💡 Hint
Count only the elements directly inside nested_list, not inside sublists.