0
0
R Programmingprogramming~10 mins

Modifying and adding elements 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 change the second element of the vector to 10.

R Programming
vec <- c(1, 2, 3)
vec[[1]] <- 10
vec
Drag options to blanks, or click blank then click option'
A2
B3
C1
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 0 which does not exist in R vectors.
Trying to assign value without specifying index.
2fill in blank
medium

Complete the code to add the number 4 at the end of the vector.

R Programming
vec <- c(1, 2, 3)
vec <- c(vec, [1])
vec
Drag options to blanks, or click blank then click option'
A5
B4
C3
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Adding the number before the vector which changes the order.
Using incorrect syntax like vec + 4 which does not add elements.
3fill in blank
hard

Fix the error in the code to correctly replace the third element with 7.

R Programming
vec <- c(1, 2, 3)
vec[[1]] <- 7
vec
Drag options to blanks, or click blank then click option'
A3
B0
C-1
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 0 which is invalid in R.
Using an index larger than the vector length, which adds a new element instead of replacing the third.
4fill in blank
hard

Fill both blanks to create a vector with elements 1, 2, 3, and then add 5 at the end.

R Programming
vec <- c([1], [2], 3)
vec <- c(vec, 5)
vec
Drag options to blanks, or click blank then click option'
A1
B2
C4
D6
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong numbers for the first two elements.
Forgetting to add 5 at the end.
5fill in blank
hard

Fill all three blanks to create a vector with elements 10, 20, 30, then replace the second element with 25.

R Programming
vec <- c([1], [2], [3])
vec[2] <- 25
vec
Drag options to blanks, or click blank then click option'
A10
B20
C30
D25
Attempts:
3 left
💡 Hint
Common Mistakes
Replacing the wrong element.
Using incorrect numbers in the vector.