0
0
R Programmingprogramming~20 mins

Named list elements in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Named List Elements Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of accessing named list elements
What is the output of the following R code?
R Programming
my_list <- list(a = 10, b = 20, c = 30)
result <- my_list$b
print(result)
A[1] 30
B[1] 10
C[1] 20
DNULL
Attempts:
2 left
💡 Hint
Remember that named list elements can be accessed by their names using the $ operator.
Predict Output
intermediate
2:00remaining
Output of modifying named list elements
What will be the output after running this R code?
R Programming
my_list <- list(x = 5, y = 15)
my_list$y <- my_list$y + 10
print(my_list$y)
AError: object 'y' not found
B[1] 15
C[1] 10
D[1] 25
Attempts:
2 left
💡 Hint
Think about how the value of 'y' is updated by adding 10.
🔧 Debug
advanced
2:00remaining
Identify the error in accessing named list elements
What error does this R code produce?
R Programming
my_list <- list(a = 1, b = 2)
print(my_list[['c']])
Alist()
BError: object 'c' not found
C[1] NA
DNULL
Attempts:
2 left
💡 Hint
Accessing a non-existent name with double brackets produces an error.
Predict Output
advanced
2:00remaining
Output of named list element extraction with double brackets
What is the output of this R code?
R Programming
my_list <- list(a = 100, b = 200)
result <- my_list[['a']]
print(result)
A[1] 100
B[1] 200
Clist(a = 100)
DError: subscript out of bounds
Attempts:
2 left
💡 Hint
Double brackets extract the element itself, not a sublist.
🧠 Conceptual
expert
3:00remaining
Number of elements in a named list after modification
Consider the following R code. How many elements does my_list have after execution?
R Programming
my_list <- list(one = 1, two = 2)
my_list$three <- 3
my_list$two <- NULL
A2
B3
C1
D0
Attempts:
2 left
💡 Hint
Assigning NULL to a list element removes it.