R(16), Factor
Factors are data objects used to classify data and store it as levels. It is useful in statistical modeling data analysis.
We can use factor()
to create factor by using vector.
is.factor()
can be used to see whether the R object is a factor.
When creating any data frame with text data columns, R language regards text columns as classified data and creates factors on them.
We can use factor()
to use change the order of the level.
new_order_data <- factor(factor_data,levels = c("East","West","North"))
We can use gl()
to generate the factor level.
gl(n, k, labels)