0
0
R Programmingprogramming~10 mins

Ordered factors 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 an ordered factor from the vector 'sizes'.

R Programming
sizes <- c("small", "medium", "large")
ordered_sizes <- factor(sizes, levels = c("small", "medium", "large"), ordered = [1])
Drag options to blanks, or click blank then click option'
A"TRUE"
BFALSE
C1
DTRUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using FALSE instead of TRUE for the 'ordered' argument.
Passing 'TRUE' as a string instead of a logical value.
2fill in blank
medium

Complete the code to check if 'ordered_sizes' is an ordered factor.

R Programming
is.ordered([1])
Drag options to blanks, or click blank then click option'
Afactor
Bsizes
Cordered_sizes
Dlevels
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the original vector instead of the factor.
Passing the function name 'factor' instead of a variable.
3fill in blank
hard

Fix the error in the code to create an ordered factor with levels 'low', 'medium', 'high'.

R Programming
levels <- c("low", "medium", "high")
values <- c("medium", "high", "low")
factor_values <- factor(values, levels = levels, ordered = [1])
Drag options to blanks, or click blank then click option'
ATRUE
B1
C"TRUE"
DFALSE
Attempts:
3 left
💡 Hint
Common Mistakes
Using FALSE or a string instead of TRUE.
Passing numeric 1 instead of logical TRUE.
4fill in blank
hard

Fill both blanks to create an ordered factor with levels 'beginner', 'intermediate', 'advanced' and check if it is ordered.

R Programming
levels <- c("beginner", "intermediate", "advanced")
skills <- c("advanced", "beginner", "intermediate")
skill_factor <- factor(skills, levels = levels, ordered = [1])
check <- is.ordered([2])
Drag options to blanks, or click blank then click option'
ATRUE
BFALSE
Cskills
Dskill_factor
Attempts:
3 left
💡 Hint
Common Mistakes
Using FALSE for the ordered argument.
Checking the original vector instead of the factor.
5fill in blank
hard

Fill all three blanks to create an ordered factor from 'grades', set levels, and check if it is ordered.

R Programming
grades <- c("B", "A", "C")
levels <- c("C", [1], "A")
ordered_grades <- factor(grades, levels = levels, ordered = [2])
result <- is.ordered([3])
Drag options to blanks, or click blank then click option'
A"B"
BTRUE
Cordered_grades
DFALSE
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out the middle level in levels.
Using FALSE for ordered argument.
Checking the original vector instead of the factor.