0
0
R Programmingprogramming~10 mins

Why vectors are the fundamental data structure in R Programming - Test Your Understanding

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

Complete the code to create a numeric vector with elements 1, 2, and 3.

R Programming
vec <- c([1])
Drag options to blanks, or click blank then click option'
A"1", "2", "3"
B1, 2, 3
Cc(1, 2, 3)
Dlist(1, 2, 3)
Attempts:
3 left
💡 Hint
Common Mistakes
Putting numbers inside quotes creates a character vector, not numeric.
Using list() creates a list, not a vector.
2fill in blank
medium

Complete the code to get the length of the vector vec.

R Programming
len <- [1](vec)
Drag options to blanks, or click blank then click option'
Alength
Bcount
Csize
Ddim
Attempts:
3 left
💡 Hint
Common Mistakes
Using dim() returns NULL for vectors.
Using size() or count() are not valid R functions.
3fill in blank
hard

Fix the error in the code to access the second element of vector vec.

R Programming
second_element <- vec[1]2
Drag options to blanks, or click blank then click option'
A[[
B(
C{
D[
Attempts:
3 left
💡 Hint
Common Mistakes
Using double brackets [[ ]] causes errors with vectors.
Using curly braces or parentheses for indexing is invalid.
4fill in blank
hard

Fill both blanks to create a vector of even numbers from 2 to 10.

R Programming
evens <- seq([1], [2], by = 2)
Drag options to blanks, or click blank then click option'
A2
B1
C10
D12
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 1 creates odd numbers.
Ending at 12 includes a number beyond 10.
5fill in blank
hard

Fill both blanks to create a named vector with scores for Alice and Bob, then access Bob's score.

R Programming
scores <- c(Alice = [1], Bob = [2])
bob_score <- scores"Bob"
Drag options to blanks, or click blank then click option'
A85
B90
C[
D$
Attempts:
3 left
💡 Hint
Common Mistakes
Using $ to access vector elements causes errors.
Mixing up Alice's and Bob's scores.