Challenge - 5 Problems
List to Vector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of unlist on nested list
What is the output of the following R code?
R Programming
my_list <- list(a = 1:3, b = list(4, 5)) result <- unlist(my_list) print(result)
Attempts:
2 left
💡 Hint
Remember that unlist flattens nested lists and preserves names.
✗ Incorrect
The unlist function converts the nested list into a named vector, flattening all elements and preserving the names from the original list.
❓ Predict Output
intermediate2:00remaining
Result of as.vector on a list
What is the output of this R code?
R Programming
my_list <- list(10, 20, 30) result <- as.vector(my_list) print(result)
Attempts:
2 left
💡 Hint
as.vector tries to simplify the list to a vector if possible.
✗ Incorrect
as.vector returns the list unchanged because the list elements are not simplified to an atomic vector.
🔧 Debug
advanced3:00remaining
Why does this unlist produce unexpected output?
Consider this code snippet:
my_list <- list(c(1, 2), c('a', 'b'))
result <- unlist(my_list)
print(result)
Why does the output contain characters instead of numbers?
R Programming
my_list <- list(c(1, 2), c('a', 'b')) result <- unlist(my_list) print(result)
Attempts:
2 left
💡 Hint
Think about how R handles vectors with mixed types.
✗ Incorrect
When unlist encounters mixed types, it coerces all elements to a common type that can hold all values, which is character in this case.
🧠 Conceptual
advanced2:00remaining
Length of vector after unlist
If you have a list like this: list(1:3, 4:6, 7:9), what is the length of the vector after applying unlist()?
R Programming
my_list <- list(1:3, 4:6, 7:9) result <- unlist(my_list) length(result)
Attempts:
2 left
💡 Hint
Count all elements inside all sublists combined.
✗ Incorrect
unlist flattens the list into a single vector containing all elements, so length is the total number of elements.
📝 Syntax
expert3:00remaining
Which code produces a numeric vector from a list of numeric vectors?
Given a list of numeric vectors, which R code correctly converts it into a single numeric vector?
R Programming
my_list <- list(c(1,2), c(3,4), c(5,6))
Attempts:
2 left
💡 Hint
Check which function flattens nested lists properly.
✗ Incorrect
unlist flattens the list into a single vector. as.vector returns the list unchanged, c() concatenates but keeps list structure, vector() creates an empty vector.