Complete the code to change the reference level of the factor to "B".
f <- factor(c("A", "B", "C")) f <- relevel(f, ref = [1]) levels(f)
The relevel() function changes the reference level of a factor. Here, setting ref = "B" makes "B" the first level.
Complete the code to set the reference level of the factor colors to "green".
colors <- factor(c("red", "green", "blue")) colors <- relevel(colors, ref = [1]) levels(colors)
Setting ref = "green" makes "green" the reference level in the factor colors.
Fix the error in the code to correctly relevel the factor f to have "low" as the reference level.
f <- factor(c("high", "medium", "low")) f <- relevel(f, ref = [1]) levels(f)
The reference level must be a string enclosed in double quotes. Using "low" is correct.
Fill both blanks to create a factor f from vals and relevel it to have "second" as the reference level.
vals <- c("first", "second", "third") f <- factor([1]) f <- relevel(f, ref = [2]) levels(f)
Use the vector vals to create the factor, then set the reference level to "second".
Fill all three blanks to create a factor f from data, relevel it to "C", and then get the levels.
data <- c("A", "B", "C", "A") f <- factor([1]) f <- relevel(f, ref = [2]) result <- levels([3])
Create the factor from data, set "C" as the reference level, and get the levels of f.