0
0
R Programmingprogramming~10 mins

Releveling 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 change the reference level of the factor to "B".

R Programming
f <- factor(c("A", "B", "C"))
f <- relevel(f, ref = [1])
levels(f)
Drag options to blanks, or click blank then click option'
A"B"
B"C"
C"A"
D"D"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a level name that does not exist in the factor.
Forgetting to put the level name inside quotes.
2fill in blank
medium

Complete the code to set the reference level of the factor colors to "green".

R Programming
colors <- factor(c("red", "green", "blue"))
colors <- relevel(colors, ref = [1])
levels(colors)
Drag options to blanks, or click blank then click option'
A"red"
B"green"
C"blue"
D"yellow"
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a level not present in the factor.
Not assigning the result back to the variable.
3fill in blank
hard

Fix the error in the code to correctly relevel the factor f to have "low" as the reference level.

R Programming
f <- factor(c("high", "medium", "low"))
f <- relevel(f, ref = [1])
levels(f)
Drag options to blanks, or click blank then click option'
A"low"
Blow
C'low'
Dlow"
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the level name.
Using mismatched or incomplete quotes.
4fill in blank
hard

Fill both blanks to create a factor f from vals and relevel it to have "second" as the reference level.

R Programming
vals <- c("first", "second", "third")
f <- factor([1])
f <- relevel(f, ref = [2])
levels(f)
Drag options to blanks, or click blank then click option'
Avals
B"first"
C"second"
Dc("first", "second", "third")
Attempts:
3 left
💡 Hint
Common Mistakes
Creating the factor from a wrong vector or literal.
Setting a reference level not present in the factor.
5fill in blank
hard

Fill all three blanks to create a factor f from data, relevel it to "C", and then get the levels.

R Programming
data <- c("A", "B", "C", "A")
f <- factor([1])
f <- relevel(f, ref = [2])
result <- levels([3])
Drag options to blanks, or click blank then click option'
Adata
B"C"
Cf
D"B"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names in any of the steps.
Setting a reference level not in the factor.