0
0
R Programmingprogramming~10 mins

Why data types matter in R 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 in R.

R Programming
numbers <- c(1, 2, 3, [1])
Drag options to blanks, or click blank then click option'
A4
B"4"
Cc(4)
DTRUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numbers makes them characters.
2fill in blank
medium

Complete the code to check the data type of the variable 'x'.

R Programming
x <- 10
class([1])
Drag options to blanks, or click blank then click option'
Ax
B10
C"x"
Dclass
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the value or variable name as a string instead of the variable itself.
3fill in blank
hard

Fix the error in the code to convert a character vector to numeric.

R Programming
chars <- c("1", "2", "3")
numbers <- as.[1](chars)
Drag options to blanks, or click blank then click option'
Acharacter
Blogical
Cfactor
Dnumeric
Attempts:
3 left
💡 Hint
Common Mistakes
Using as.character() or as.factor() which do not convert to numeric.
4fill in blank
hard

Fill both blanks to create a logical vector and check its type.

R Programming
flags <- c(TRUE, FALSE, TRUE)
type <- class([1])
print([2])
Drag options to blanks, or click blank then click option'
Aflags
Btype
C"flags"
Dclass
Attempts:
3 left
💡 Hint
Common Mistakes
Passing strings instead of variables, or printing the wrong variable.
5fill in blank
hard

Fill all three blanks to create a factor and check its levels.

R Programming
colors <- factor(c("red", "blue", "red"))
[1] <- levels([2])
print([3])
Drag options to blanks, or click blank then click option'
Avec
Bcolors
Clevels_vec
Dlevels_colors
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names or forgetting to store levels before printing.