0
0
R Programmingprogramming~10 mins

Numeric and character 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 numeric vector with values 1, 2, and 3.

R Programming
vec <- c([1])
Drag options to blanks, or click blank then click option'
A1, 2, 3
B"1", "2", "3"
Cc(1, 2, 3)
D1:3
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around numbers creates character vectors instead of numeric.
Using c(1:3) inside c() is redundant.
2fill in blank
medium

Complete the code to create a character vector with the names "apple", "banana", and "cherry".

R Programming
fruits <- c([1])
Drag options to blanks, or click blank then click option'
Ac("apple", "banana", "cherry")
Bapple, banana, cherry
C"apple", "banana", "cherry"
D'apple', 'banana', 'cherry'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes makes R think these are variable names, causing errors.
Using single quotes is allowed but less common in R.
3fill in blank
hard

Fix the error in the code to create a numeric vector from 5 to 10.

R Programming
numbers <- [1](5, 10)
Drag options to blanks, or click blank then click option'
Ac
Brange
Cvector
Dseq
Attempts:
3 left
💡 Hint
Common Mistakes
Using c(5, 10) creates a vector with only two numbers, not a sequence.
Using vector() creates an empty vector, not a sequence.
4fill in blank
hard

Fill both blanks to create a character vector of three fruits and check its type.

R Programming
fruits <- c([1])
is_char <- is.[2](fruits)
Drag options to blanks, or click blank then click option'
A"orange", "pear", "grape"
Bnumeric
Ccharacter
D"apple", "banana", "cherry"
Attempts:
3 left
💡 Hint
Common Mistakes
Using numeric type check on character vectors causes FALSE result.
Not quoting fruit names causes errors.
5fill in blank
hard

Fill all three blanks to create a numeric vector, get its length, and access the second element.

R Programming
nums <- c([1])
len <- length([2])
second <- [3][2]
Drag options to blanks, or click blank then click option'
A10, 20, 30
Bnums
Dc(10, 20, 30)
Attempts:
3 left
💡 Hint
Common Mistakes
Putting c(10, 20, 30) inside c() causes nested vectors.
Using wrong variable names causes errors.