How to Apply the gl() Function in R (Example Code)
In this R tutorial you’ll learn how to specify a variable with factor levels using the gl function.
Example: Generate Factor Variable Using gl() Function
my_vec <- gl(n = 4, k = 3) # Using gl function my_vec # [1] 1 1 1 2 2 2 3 3 3 4 4 4 # Levels: 1 2 3 4 |
my_vec <- gl(n = 4, k = 3) # Using gl function my_vec # [1] 1 1 1 2 2 2 3 3 3 4 4 4 # Levels: 1 2 3 4