0
0
R Programmingprogramming~10 mins

Named vectors 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 create a named vector with names 'a', 'b', 'c'.

R Programming
vec <- c(1, 2, 3)
names(vec) <- [1]
Drag options to blanks, or click blank then click option'
Ac(a, b, c)
Blist('a', 'b', 'c')
Cc('a', 'b', 'c')
Dc("a", "b")
Attempts:
3 left
💡 Hint
Common Mistakes
Using list() instead of c() for names.
Not using quotes around names.
Assigning fewer names than vector elements.
2fill in blank
medium

Complete the code to access the element named 'b' from the named vector.

R Programming
vec <- c(x=10, y=20, b=30)
value <- vec[[1]]
Drag options to blanks, or click blank then click option'
A"b"
B2
Cb
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the name without quotes.
Using the wrong index number.
Confusing names with variable names.
3fill in blank
hard

Fix the error in the code to correctly assign names to the vector.

R Programming
vec <- c(5, 10, 15)
names(vec) <- [1]
Drag options to blanks, or click blank then click option'
Ac(1, 2, 3)
Bc('one', 'two')
Clist('a', 'b', 'c')
Dc('first', 'second', 'third')
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning fewer names than vector elements.
Using numeric vectors instead of character vectors for names.
Using list() instead of c() for names.
4fill in blank
hard

Fill both blanks to create a named vector and access the element named 'green'.

R Programming
colors <- c([1])
names(colors) <- c('red', 'green', 'blue')
value <- colors[[2]]
Drag options to blanks, or click blank then click option'
A5, 10, 15
B"green"
C"red"
Dc(5, 10, 15)
Attempts:
3 left
💡 Hint
Common Mistakes
Not using c() to create the vector.
Accessing element without quotes.
Using wrong names for access.
5fill in blank
hard

Fill all three blanks to create a named vector, assign names, and access the element named 'second'.

R Programming
vals <- [1]
names(vals) <- [2]
result <- vals[[3]]
Drag options to blanks, or click blank then click option'
Ac(100, 200, 300)
Bc('first', 'second', 'third')
C"second"
Dlist(100, 200, 300)
Attempts:
3 left
💡 Hint
Common Mistakes
Using list() instead of c() for vectors.
Assigning names with wrong length.
Accessing elements without quotes.