0
0
R Programmingprogramming~10 mins

Factor creation 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 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'
Amatrix
Bas.character
Clist
Dfactor
Attempts:
3 left
💡 Hint
Common Mistakes
Using as.character() instead of factor()
Using list() which creates a list, not a factor
2fill in blank
medium

Complete 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'
Ac("red", "blue", "green")
Blist("red", "blue", "green")
Cc(1, 2, 3)
Dc("yellow", "purple")
Attempts:
3 left
💡 Hint
Common Mistakes
Using list() instead of c() for levels
Using numeric values instead of character strings for levels
3fill in blank
hard

Fix 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'
Ac(sizes)
Bsize
Csizes
Dfactor(sizes)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong variable name 'size'
Wrapping factor() inside factor() causing nested factors
4fill in blank
hard

Fill 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'
Ac("small", "medium", "large")
BTRUE
CFALSE
Dc("large", "medium", "small")
Attempts:
3 left
💡 Hint
Common Mistakes
Using unordered levels or reversed order
Setting ordered to FALSE or omitting it
5fill in blank
hard

Fill 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'
Ac("a", "b", "c")
Bc("apple", "banana", "cherry")
CFALSE
DTRUE
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up levels and labels
Setting ordered to TRUE when not needed