Challenge - 5 Problems
Mixed Types List Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this R code with mixed types in a list?
Consider the following R code that creates a list with mixed types. What will be the output when printing the list?
R Programming
my_list <- list(42, "hello", TRUE, 3.14) print(my_list)
Attempts:
2 left
💡 Hint
Remember that R lists can hold elements of different types without coercion.
✗ Incorrect
In R, lists can hold elements of different types without converting them. Printing a list shows each element with its type and value.
🧠 Conceptual
intermediate1:30remaining
Why can R lists hold mixed types?
Why are R lists able to hold elements of different types, unlike atomic vectors?
Attempts:
2 left
💡 Hint
Think about how lists store their elements internally.
✗ Incorrect
Lists in R are recursive objects that can store pointers to any type of R object, allowing mixed types without coercion.
🔧 Debug
advanced2:00remaining
What error occurs when mixing types in a vector?
What happens when you try to create a vector with mixed types like c(1, "two", TRUE) in R?
R Programming
vec <- c(1, "two", TRUE) print(vec)
Attempts:
2 left
💡 Hint
Vectors in R coerce elements to a common type.
✗ Incorrect
When mixing types in a vector, R coerces all elements to the most flexible type, here character, so numbers and logicals become strings.
📝 Syntax
advanced1:30remaining
Which code correctly creates a list with mixed types?
Which of the following R code snippets correctly creates a list containing a number, a string, and a logical value?
Attempts:
2 left
💡 Hint
Remember the syntax for list elements in R.
✗ Incorrect
The list() function uses commas to separate elements. Using c() creates a vector which coerces types. Semicolons or missing commas cause syntax errors.
🚀 Application
expert2:30remaining
How many elements does this list contain after modification?
Given the code below, how many elements does the list 'my_list' contain after running all lines?
R Programming
my_list <- list(1, "a", FALSE) my_list[[4]] <- 3.14 my_list[[2]] <- list("nested", 99) length(my_list)
Attempts:
2 left
💡 Hint
Assigning to a new index extends the list length.
✗ Incorrect
Assigning to my_list[[4]] adds a new element, increasing length to 4. Replacing my_list[[2]] with another list does not change length.