Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a factor from the vector 'colors'.
R Programming
colors <- c("red", "blue", "green", "blue") factor_colors <- [1](colors)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using as.character() instead of factor()
Using list() which creates a list, not a factor
✗ Incorrect
The factor() function creates a factor from a vector in R.
2fill in blank
mediumComplete the code to create a factor with specified levels.
R Programming
colors <- c("red", "blue", "green", "blue") factor_colors <- factor(colors, levels = [1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using list() instead of c() for levels
Using numeric values instead of character strings for levels
✗ Incorrect
The levels argument expects a character vector of the factor levels.
3fill in blank
hardFix the error in the code to create a factor from 'sizes'.
R Programming
sizes <- c("small", "medium", "large", "medium") factor_sizes <- factor([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong variable name 'size'
Wrapping factor() inside factor() causing nested factors
✗ Incorrect
The variable name is sizes. Using it directly creates the factor.
4fill in blank
hardFill both blanks to create an ordered factor with levels from small to large.
R Programming
sizes <- c("small", "medium", "large", "medium") factor_sizes <- factor(sizes, levels = [1], ordered = [2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unordered levels or reversed order
Setting ordered to FALSE or omitting it
✗ Incorrect
Levels must be in order from smallest to largest, and ordered = TRUE makes the factor ordered.
5fill in blank
hardFill all three blanks to create a factor from 'fruits' with levels and labels.
R Programming
fruits <- c("a", "b", "c", "a") factor_fruits <- factor(fruits, levels = [1], labels = [2], ordered = [3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up levels and labels
Setting ordered to TRUE when not needed
✗ Incorrect
Levels are the original codes, labels are the descriptive names, and ordered is FALSE for unordered factors.