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

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top