Challenge - 5 Problems
List Creation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of nested list creation
What is the output of this R code that creates a nested list?
R Programming
my_list <- list(a = 1:3, b = list(x = 10, y = 20)) str(my_list)
Attempts:
2 left
💡 Hint
Remember that list() can contain other lists as elements.
✗ Incorrect
The code creates a list with two elements: 'a' is a vector of integers 1 to 3, and 'b' is another list with elements 'x' and 'y'. Printing shows the structure with nested lists.
🧠 Conceptual
intermediate1:30remaining
Understanding list element types
Which statement about lists in R is true?
Attempts:
2 left
💡 Hint
Think about what you can store inside a list in R.
✗ Incorrect
Lists in R are flexible containers that can hold elements of different types, including numbers, strings, vectors, and even other lists.
🔧 Debug
advanced2:00remaining
Identify the error in list creation
What error does this R code produce?
R Programming
my_list <- list(1, 2, 3 print(my_list)
Attempts:
2 left
💡 Hint
Check if all parentheses are closed properly.
✗ Incorrect
The code is missing a closing parenthesis for the list() function, causing an unexpected end of input error.
❓ Predict Output
advanced1:30remaining
Output of list element modification
What is the output after modifying a list element in R?
R Programming
my_list <- list(a = 5, b = 10) my_list$a <- my_list$a + 3 print(my_list$a)
Attempts:
2 left
💡 Hint
Look at how the element 'a' is changed by adding 3.
✗ Incorrect
The element 'a' initially is 5, adding 3 makes it 8, so printing my_list$a outputs 8.
📝 Syntax
expert2:00remaining
Correct syntax for creating a list with named and unnamed elements
Which option correctly creates a list with one named element 'x' and two unnamed elements 10 and 20?
Attempts:
2 left
💡 Hint
Named elements can appear anywhere, unnamed elements keep their order.
✗ Incorrect
Option D creates a list with named element 'x' = 5, followed by unnamed elements 10 and 20. This is valid syntax.