Challenge - 5 Problems
Vector Indexing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:00remaining
What is the output of this R code using 1-based indexing?
Consider the vector
v <- c(10, 20, 30, 40, 50). What is the output of v[3]?R Programming
v <- c(10, 20, 30, 40, 50) v[3]
Attempts:
2 left
💡 Hint
Remember R vectors start counting at 1, not 0.
✗ Incorrect
In R, vector indexing starts at 1, so v[3] returns the third element, which is 30.
❓ Predict Output
intermediate1:00remaining
What does this R code output when indexing with a vector?
Given
v <- c(5, 10, 15, 20, 25), what is the output of v[c(2, 4)]?R Programming
v <- c(5, 10, 15, 20, 25) v[c(2, 4)]
Attempts:
2 left
💡 Hint
Indexing with a vector returns elements at those positions.
✗ Incorrect
v[c(2,4)] returns the elements at positions 2 and 4, which are 10 and 20.
🧠 Conceptual
advanced1:00remaining
What error does this R code raise when indexing with zero?
What happens when you run
v <- c(1,2,3); v[0] in R?R Programming
v <- c(1,2,3) v[0]
Attempts:
2 left
💡 Hint
In R, zero is a special index that means no elements.
✗ Incorrect
Indexing with 0 returns an empty vector of the same type, no error is raised.
❓ Predict Output
advanced1:30remaining
What is the output of negative indexing in R?
Given
v <- c(2, 4, 6, 8, 10), what does v[-c(1,3)] return?R Programming
v <- c(2, 4, 6, 8, 10) v[-c(1,3)]
Attempts:
2 left
💡 Hint
Negative indices exclude those positions from the result.
✗ Incorrect
v[-c(1,3)] excludes elements at positions 1 and 3, returning elements at positions 2,4,5.
❓ Predict Output
expert1:30remaining
What is the output of this complex vector indexing in R?
Given
v <- c(3, 6, 9, 12, 15), what is the output of v[c(TRUE, FALSE, TRUE, FALSE, TRUE)]?R Programming
v <- c(3, 6, 9, 12, 15) v[c(TRUE, FALSE, TRUE, FALSE, TRUE)]
Attempts:
2 left
💡 Hint
Logical vectors select elements where TRUE appears.
✗ Incorrect
The logical vector selects elements at positions 1,3,5 which are 3, 9, and 15.