0
0
R Programmingprogramming~20 mins

List creation in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
List Creation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A
List of 3
 $ a: int 1
 $ b: int 2
 $ x: int 10
B
[1] 1 2 3
[1] 10 20
C
List of 2
 $ a: int [1:3] 1 2 3
 $ b:List of 2
  ..$ x: num 10
  ..$ y: num 20
DError in list(a = 1:3, b = list(x = 10, y = 20)) : object not found
Attempts:
2 left
💡 Hint
Remember that list() can contain other lists as elements.
🧠 Conceptual
intermediate
1:30remaining
Understanding list element types
Which statement about lists in R is true?
ALists can contain elements of different types, including other lists.
BLists can only contain elements of the same type, like vectors.
CLists are immutable and cannot be changed after creation.
DLists automatically convert all elements to characters.
Attempts:
2 left
💡 Hint
Think about what you can store inside a list in R.
🔧 Debug
advanced
2: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)
ANo error, prints list with elements 1, 2, 3
BError: unexpected end of input
CError: object 'my_list' not found
DError: unexpected symbol in 'print(my_list)'
Attempts:
2 left
💡 Hint
Check if all parentheses are closed properly.
Predict Output
advanced
1: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)
A[1] 8
B[1] 5
CError: object 'a' not found
D[1] 10
Attempts:
2 left
💡 Hint
Look at how the element 'a' is changed by adding 3.
📝 Syntax
expert
2: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?
Alist(x = 10, 20, 5)
Blist(5, x = 10, 20)
Clist(10, 20, x = 5)
Dlist(x = 5, 10, 20)
Attempts:
2 left
💡 Hint
Named elements can appear anywhere, unnamed elements keep their order.