Attributes of Factors in R Language
- x: It is the vector that needs to be converted into a factor.
- Levels: It is a set of distinct values which are given to the input vector x.
- Labels: It is a character vector corresponding to the number of labels.
- Exclude: This will mention all the values you want to exclude.
- Ordered: This logical attribute decides whether the levels are ordered.
- nmax: It will decide the upper limit for the maximum number of levels.
R Factors
Factors in R Programming Language are data structures that are implemented to categorize the data or represent categorical data and store it on multiple levels.
They can be stored as integers with a corresponding label to every unique integer. The R factors may look similar to character vectors, they are integers and care must be taken while using them as strings. The R factor accepts only a restricted number of distinct values. For example, a data field such as gender may contain values only from female, male, or transgender.
In the above example, all the possible cases are known beforehand and are predefined. These distinct values are known as levels. After a factor is created it only consists of levels that are by default sorted alphabetically.
Contact Us