Q&A
Ask and answer questions to make information more available to wider audiences.
Kennedy Ledford @ledfordkennedy   22, Aug 2023 12:00 AM
Categorical arrays vs Character arrays
What are the advantages of using Categorical arrays vs Character arrays?
answers 2
 
Answer 1
Drake Boot @bootdrake85   31, Aug 2023 03:22 PM
Furthermore, to compare values in Character arrays, you must use the strcmp function which can be cumbersome. With categorical arrays, you can use the logical operator eq (==) to compare elements in the same way that you compare numeric arrays.

When using a Character array as a categorical array the categories are defined as character vectors, which can be costly to store and manipulate. Categorical arrays store only one copy of each category name, often reducing the amount of memory required to store the array.

 
Answer 2
Drake Boot @bootdrake85   31, Aug 2023 03:22 PM
Categorical arrays are convenient and memory-efficient containers for non-numeric data with values from a finite set of discrete categories. They are especially useful when the categories have a meaningful mathematical ordering, such as an array with entries from the discrete set of categories {'small','medium','large'} where small < medium < large.

An ordering other than alphabetical order is not possible with character arrays. Thus, inequality comparisons, such as greater and less than, are not possible. With categorical arrays, you can use relational operations to test for equality and perform element-wise comparisons that have a meaningful mathematical ordering.