0
0
R Programmingprogramming~10 mins

Negative indexing for exclusion in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to exclude the second element from the vector.

R Programming
vec <- c(10, 20, 30, 40)
result <- vec[[1]]
print(result)
Drag options to blanks, or click blank then click option'
A-2
B2
C-1
Dc(2)
Attempts:
3 left
💡 Hint
Common Mistakes
Using positive index includes the element instead of excluding it.
2fill in blank
medium

Complete the code to exclude the first and third elements from the vector.

R Programming
vec <- c(5, 15, 25, 35)
result <- vec[[1]]
print(result)
Drag options to blanks, or click blank then click option'
A-c(1, 3)
Bc(1, 3)
C-c(2, 4)
Dc(2, 4)
Attempts:
3 left
💡 Hint
Common Mistakes
Using positive indices includes those elements instead of excluding them.
3fill in blank
hard

Fix the error in the code to exclude the last element from the vector.

R Programming
vec <- c(2, 4, 6, 8)
result <- vec[[1]]
print(result)
Drag options to blanks, or click blank then click option'
Ac(length(vec))
Blength(vec)
C-length(vec)
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using positive length(vec) includes only the last element instead of excluding it.
4fill in blank
hard

Fill both blanks to exclude the second and fourth elements from the vector.

R Programming
vec <- c(3, 6, 9, 12, 15)
result <- vec[[1]([2])]
print(result)
Drag options to blanks, or click blank then click option'
A-c
Bc
C2, 4
D1, 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using positive indices includes elements instead of excluding them.
5fill in blank
hard

Fill all three blanks to exclude the first, third, and fifth elements from the vector.

R Programming
vec <- c(7, 14, 21, 28, 35, 42)
result <- vec[[1]([2])]
print(result)

# The excluded elements are [3].
Drag options to blanks, or click blank then click option'
A-c
Bc
C1, 3, 5
D7, 21, 35
Attempts:
3 left
💡 Hint
Common Mistakes
Using positive indices includes elements instead of excluding them.