Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numbers makes them characters.
✗ Incorrect
The vector should contain numeric values. Using 4 (without quotes) keeps it numeric.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the value or variable name as a string instead of the variable itself.
✗ Incorrect
Use the variable name 'x' inside the class() function to check its data type.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using as.character() or as.factor() which do not convert to numeric.
✗ Incorrect
Use as.numeric() to convert character values that represent numbers into numeric type.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing strings instead of variables, or printing the wrong variable.
✗ Incorrect
Use the variable 'flags' to get its class, then print the 'type' variable.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names or forgetting to store levels before printing.
✗ Incorrect
Create a variable to store levels, get levels of 'colors', then print that variable.