Complete the code to create a numeric vector with elements 1, 2, and 3.
vec <- c([1])list() creates a list, not a vector.The c() function combines values into a vector. Using 1, 2, 3 creates a numeric vector.
Complete the code to get the length of the vector vec.
len <- [1](vec)dim() returns NULL for vectors.size() or count() are not valid R functions.The length() function returns the number of elements in a vector.
Fix the error in the code to access the second element of vector vec.
second_element <- vec[1]2
[[ ]] causes errors with vectors.Use single square brackets [] to access elements of a vector by position.
Fill both blanks to create a vector of even numbers from 2 to 10.
evens <- seq([1], [2], by = 2)
The seq() function creates sequences. Starting at 2 and ending at 10 with step 2 gives even numbers.
Fill both blanks to create a named vector with scores for Alice and Bob, then access Bob's score.
scores <- c(Alice = [1], Bob = [2]) bob_score <- scores"Bob"
Named vectors assign values with names. Use square brackets with the name to access an element.