Challenge - 5 Problems
Vector Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of vector recycling in R
What is the output of this R code snippet?
R Programming
x <- c(1, 2, 3) y <- c(10, 20) z <- x + y print(z)
Attempts:
2 left
💡 Hint
Remember how R recycles shorter vectors to match the length of longer vectors.
✗ Incorrect
In R, when you add two vectors of different lengths, the shorter one is recycled to match the longer one. Here, y = c(10, 20) is recycled to c(10, 20, 10). So, z = c(1+10, 2+20, 3+10) = c(11, 22, 13).
🧠 Conceptual
intermediate2:00remaining
Why vectors are fundamental in R
Which statement best explains why vectors are the fundamental data structure in R?
Attempts:
2 left
💡 Hint
Think about how R handles data and operations on collections of values.
✗ Incorrect
Vectors are fundamental because they provide a simple and consistent way to store sequences of data of the same type and allow efficient vectorized operations, which is core to R's design.
🔧 Debug
advanced2:00remaining
Identify the error in vector subsetting
What error will this R code produce and why?
R Programming
v <- c(5, 10, 15) print(v["2"])
Attempts:
2 left
💡 Hint
Check the type of the index used for subsetting a vector.
✗ Incorrect
In R, numeric vectors are indexed by numeric or logical values. Using a character string as an index without names causes an error.
📝 Syntax
advanced2:00remaining
Correct vector creation syntax
Which option correctly creates a numeric vector with elements 4, 5, and 6 in R?
Attempts:
2 left
💡 Hint
Remember the function used to combine elements into a vector.
✗ Incorrect
The function c() combines values into a vector. Other options are either invalid syntax or incorrect function usage.
🚀 Application
expert2:00remaining
Vectorized operation result
Given the vectors a <- c(2, 4, 6) and b <- c(1, 3, 5), what is the result of the expression a * b + 1?
R Programming
a <- c(2, 4, 6) b <- c(1, 3, 5) result <- a * b + 1 print(result)
Attempts:
2 left
💡 Hint
Multiply element-wise then add 1 to each element.
✗ Incorrect
Element-wise multiplication: (2*1, 4*3, 6*5) = (2, 12, 30). Adding 1 to each gives (3, 13, 31).