0
0
R Programmingprogramming~20 mins

Negative indexing for exclusion in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Negative Indexing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of negative indexing to exclude elements
What is the output of the following R code?
R Programming
x <- c(10, 20, 30, 40, 50)
result <- x[-c(2, 4)]
print(result)
A[1] 10 20 30 40 50
B[1] 20 40
C[1] 10 30 40 50
D[1] 10 30 50
Attempts:
2 left
💡 Hint
Negative indexing in R removes the elements at the specified positions.
Predict Output
intermediate
2:00remaining
Negative indexing with single element exclusion
What will be printed by this R code?
R Programming
y <- c('a', 'b', 'c', 'd')
print(y[-3])
A[1] "c"
B[1] "a" "b" "d"
C[1] "a" "b" "c" "d"
D[1] "a" "c" "d"
Attempts:
2 left
💡 Hint
Negative indexing removes the element at the given position.
🔧 Debug
advanced
2:00remaining
Identify the error in negative indexing usage
What error does this R code produce?
R Programming
z <- c(5, 10, 15, 20)
print(z[-c(2, -3)])
AError: only 0's may be mixed with negative subscripts
B[1] 5 15 20
C[1] 5 10 20
DError: invalid subscript type 'list'
Attempts:
2 left
💡 Hint
Negative and positive indices cannot be mixed in the same subscript.
🧠 Conceptual
advanced
1:30remaining
Length of vector after negative indexing exclusion
Given the vector v <- 1:8, what is the length of v[-c(1, 3, 5)]?
A5
B6
C8
D3
Attempts:
2 left
💡 Hint
Negative indexing removes the specified elements from the vector.
Predict Output
expert
2:30remaining
Output of negative indexing with repeated indices
What is the output of this R code?
R Programming
w <- c(2, 4, 6, 8, 10)
print(w[-c(2, 2, 4)])
A[1] 2 6 8 10
B[1] 4 8
C[1] 2 6 10
DError: invalid subscript type 'double'
Attempts:
2 left
💡 Hint
Repeated indices in negative indexing exclude the element only once.