Complete the code to access the first element of the vector v.
v <- c(10, 20, 30) first_element <- v[1]1
In R, single square brackets [] are used to access elements of a vector by index.
Complete the code to extract the first element from the list lst.
lst <- list(a = 5, b = 10) first_element <- lst[1]1
Double square brackets [[ ]] extract the element itself from a list, not a sublist.
Fix the error in the code to access the element named 'b' in the list lst.
lst <- list(a = 5, b = 10) value <- lst[1]b
The dollar sign $ is used to access named elements in a list by name without quotes.
Fill both blanks to create a named vector and access the element named 'second'.
vec <- c(first = 1, second = 2, third = 3) value <- vec[1]"second"[2]
Single brackets [] with quotes access named elements in a vector and return a vector of length 1.
Complete the code to create a list with named elements and access the element named 'age'.
person <- list(name = "Alice", age = 30, city = "NY") age_value <- person[1]"age"
Use double brackets [[ ]] with quotes to extract the element itself from a list by name.