# change order of levels, reference

#### Reordering Levels and Setting Reference Level in R

```
# Create a sample factor variable
x <- factor(c("A", "B", "C", "A", "B", "C"))
x
# Reorder levels
x <- factor(x, levels = c("B", "A", "C"))
x
# Set reference level
x <- relevel(x, ref = "B")
x
```