In R programming language, you can create R factors using the factor() function. The factor() function takes a vector or a variable as input and converts it into a factor. Here's an example code snippet:
# Create a vector of categories
categories <- c("A", "B", "C", "A", "B", "C", "A", "B", "C")
# Convert the vector into a factor
factor_variable <- factor(categories)
# Print the factor
print(factor_variable)
Output:
[1] A B C A B C A B C
Levels: A B C
In the above example, the vector categories is converted into a factor factor_variable using the factor() function. The output shows the levels (categories) of the factor.