Complete the code to access the first element of the vector.
vec <- c(10, 20, 30) first_element <- vec[[1]]
In R, vector indexing starts at 1, so the first element is accessed with index 1.
Complete the code to access the third element of the vector.
numbers <- c(5, 15, 25, 35) third <- numbers[[1]]
The third element is accessed with index 3 because R uses 1-based indexing.
Fix the error in the code to correctly access the second element.
values <- c(100, 200, 300) second_value <- values[[1]]
Index 2 accesses the second element in R vectors.
Fill both blanks to create a vector of squares for elements greater than 2.
vec <- c(1, 2, 3, 4, 5) squares <- vec[vec [1] 2]^[2] 2
We select elements greater than 2 using > and square them using the ^ operator.
Complete the code to access the last element of the vector.
vec <- c(10, 20, 30, 40, 50) last_element <- vec[[1]]
In R, the last element can be accessed using length(vec) as the index since indexing is 1-based.
