Recall & Review
beginner
What is a factor in R?
A factor in R is a data type used to represent categorical variables. It stores categories as levels and is useful for statistical modeling and plotting.
Click to reveal answer
beginner
How do you create a factor from a character vector in R?
Use the function
factor(). For example: factor(c('red', 'blue', 'red')) creates a factor with levels 'blue' and 'red'.Click to reveal answer
intermediate
Why are factors important in plotting with ggplot2?
Factors control the order and grouping of categories in plots. They help ggplot2 know how to display categorical data on axes or in colors.
Click to reveal answer
intermediate
How can you change the order of levels in a factor?
Use
factor(x, levels = c(...)) to specify the order of levels. This changes how categories appear in analysis and plots.Click to reveal answer
beginner
What happens if you plot a numeric variable as a factor?
The numeric values are treated as categories, not numbers. The plot will show discrete groups instead of a continuous scale.
Click to reveal answer
Which R function converts a character vector to a factor?
✗ Incorrect
The function
factor() converts character vectors to factors.What does the
levels argument in factor() do?✗ Incorrect
The
levels argument sets the order of categories in the factor.In ggplot2, how does a factor affect the x-axis?
✗ Incorrect
Factors make ggplot2 display categories as discrete groups on the axis.
If you plot a numeric variable as a factor, what will you see?
✗ Incorrect
Plotting numeric data as a factor treats numbers as categories, showing discrete groups.
How do you check the levels of a factor variable in R?
✗ Incorrect
The
levels() function shows the categories of a factor.Explain what a factor is in R and why it is useful for analysis and plotting.
Think about how categories are stored and used in graphs.
You got /5 concepts.
Describe how you would change the order of categories in a factor and why this might matter in a plot.
Consider how the order affects what you see on the graph.
You got /5 concepts.