R Factor Data Type | R Datatypes Factors - r - learn r - r programming

• In datatypes, arrays are a special vector.
• Arrays are similar to matrices but we can have more than two dimensions.
• Factors are the data objects which are used to categorize the data and store it as levels.
• They can store both strings and integers.
• They are useful in the columns which have a limited number of unique values. Like "Male, "Female" and True, False etc.
• They are useful in data analysis for statistical modeling.
• Factors are created using the factor () function by taking a vector as input.

Code Explanation:

1. wikitechy is specifying to string variable. Here ('1','1','2','4','3','3','2','1') is data elements.
2. Here in this example, factor(wikitechy) is used to create an objects of wikitechy variable.
3. Here print() is used to print the value, that value stored in wikitechy variable.
4. The nlevels(wikitechy)) functions is gives the count of levels.

Sample Output:

1. Here in this output we display 1 1 2 4 3 3 2 1 which specifying to data elements. The levels of a factor are used when displaying the factor's values 1 2 3 4.
2. Here in this output we display 4 which specifies to count of levels.