categorical
Array representing categorical data.
A categorical
array represents an array of values that correspond
to a finite set of discrete categories, which can be either ordinal (having
a mathematical ordering) or nominal. It is an efficient way to define
groups of rows in a table or to other types of variables.
Each categorical
array stores the list of categories as a cell array
of character vectors and a numeric array of uint16
type as indices
to the categories. The categorical array may also store elements of
undefined categorical values, which represent the absense of a given
category and correspond to the NaN
value for numeric arrays or in
general to the missing value for other data types.
categorical
arrays do not have any public properties, which can be
indexed by using dot notation similarily to structures. However, there are
several methods which can be used to modify their categories once they are
constructed.
Source Code: categorical
Create a new array of categorical values.
A is the array of values to convert to categoricals.
valueset is the set of all values from which A is drawn. If omitted, it defaults to the unique values in A.
catnames is a list of category names corresponding to valueset. If omitted, it defaults to valueset, converted to strings.
Ordinal is a logical indicating whether the category values in C have a numeric ordering relationship. Defaults to false.
Protected indicates whether C should be protected, which prevents the addition of new categories to the array. Defaults to false.
C = categorical ()
returns an empty categorical array.
See also: categories, discretize, iscategorical
Get display formatted strings for each element of a categorical array.
cstr = dispstrings (C)
returns a cellstr array of
character vectors, cstr, which has the same size as the input
categorical C.
Convert categorical array to a cell array of character vectors.
cstr = cellstr (C)
returns a cellstr array of
character vectors, cstr, which has the same size as the input
categorical C.
Convert categorical array to a double array.
out = double (C)
returns a double array indexing the
categories in C. Categorical elements of undefined category are
returned as NaN
.
Convert categorical array to a single array.
out = single (C)
returns a single array indexing the
categories in C. Categorical elements of undefined category are
returned as NaN
.
Convert categorical array to a int64 array.
out = int64 (C)
returns a int64
array
indexing the categories in C. Categorical elements of undefined
category are returned as 0
.
Convert categorical array to a int32 array.
out = int32 (C)
returns a int32
array
indexing the categories in C. Categorical elements of undefined
category are returned as 0
.
Convert categorical array to a int16 array.
out = int16 (C)
returns a int16
array
indexing the categories in C. Categorical elements of undefined
category are returned as 0
. Note that the returned category
indices saturate to intmax ('int16')
, which is 32767.
Convert categorical array to a int8 array.
out = int8 (C)
returns a int8
array
indexing the categories in C. Categorical elements of undefined
category are returned as 0
. Note that the returned category
indices saturate to intmax ('int8')
, which is 127.
Convert categorical array to a uint64 array.
out = uint64 (C)
returns a uint64
array
indexing the categories in C. Categorical elements of undefined
category are returned as 0
.
Convert categorical array to a uint32 array.
out = uint32 (C)
returns a uint32
array
indexing the categories in C. Categorical elements of undefined
category are returned as 0
.
Convert categorical array to a uint16 array.
out = uint16 (C)
returns a uint16
array
indexing the categories in C. Categorical elements of undefined
category are returned as 0
.
Convert categorical array to a int8 array.
out = uint8 (C)
returns a uint8
array
indexing the categories in C. Categorical elements of undefined
category are returned as 0
. Note that the returned category
indices saturate to intmax ('uint8')
, which is 255.
Display summary of categorical array.
summary (C)
displays the number of elements in the
categorical array C that are equal to each category of C.
Any undefined elements in C are summed together and displayed as
<undefined>
.
List of categories in categorical array.
cstr = categories (C)
returns a cell array of
character vectors with the names of the categories in C.
Size of a categorical array.
sz = size (C)
returns a row vector with the size
(number of elements) of each dimension for the calendar duration array
C.
dim_sz = size (C, dim)
returns the size of
the corresponding dimension specified in dim. If dim is a
vector, then dim_sz is a vector of the same length and with each
element corresponding to a specified dimension. Multiple dimensions may
also be specified as separate arguments.
With a single output argument, size
returns a row vector. When
called with multiple output arguments, size
returns the size of
dimension N in the Nth argument.
Number of dimensions in a categorical array.
out = ndims (calD)
returns the number of dimensions
of the calendar duration array calD.
Total number of elements in a categorical array.
For compatibility reasons with Octave’s OOP interface and subsasgn
behavior, categorical’s numel
is defined to always return 1.
Test for categories in a categorical array.
TF = iscategory (C, catnames)
returns a logical
array TF of the same size as catnames containing true
for each corresponding element of catnames that is a category in
categorical array C and false
otherwise.
Return true if categorical array is a column vector.
Return true if categorical array is empty.
Return true if categorical arrays are equal.
Return true if categorical arrays are equal under the additional
assumption that NaN == NaN
.
Return true if categorical array is a 2-D array.
'rows'
)Test for categorical elements in a set.
TF = ismember (A, B)
returns a logical array
TF of the same size as A containing true
for each
corresponding element of A that is in B and false
otherwise. If A and B are both ordinal, they must both have
the same ordered set of categories. If neither A nor B are
ordinal, then this restriction is relaxed and comparison is performed
using the category names. Comparison between an ordinal and an unordered
categorical array is not allowed. A or B may also be a
string array or a cell array of character vectors containing one or
multiple category names to compare against.
TF = ismember (A, B,
only
applies to categorical matrices with the same number of columns, in which
case the logical vector TF contains 'rows'
)true
for each row of
A that is also a row in B. TF has the size number of
rows as A.
[TF, index] = ismember (A, B)
also returns
an index array of the same size as A containing the lowest index in
B for each element of A that is a member of B and 0
otherwise. If the 'rows'
optional argument is used, then the
returning index is a column vector with the same rows as A and it
contains the lowest index in B for each row of A that is a
member of B and 0 otherwise.
Test if categorical array is ordinal.
Test if categorical array is protected.
Return true if categorical array is a row vector.
Return true if categorical array is a scalar.
Test for undefined elements in categorical array.
TF = isundefined (C)
returns a logical array TF
of the same size as C containing true
for each
corresponding element of C that does not have a value from one of
the categories in C and false
otherwise.
Return true if categorical array is a vector.
'After'
, catname)'Before'
, catname)Add categories to categorical array.
B = addcats (A, newcats)
appends new categories
specified in newcats to the categorical array A at the end of
any existing categories. The output categorical array B does not
contain elements that belong to the newly added categories.
B = addcats (…,
adds
the categories after the existing category specified by catname.
'After'
, catname)
B = addcats (…,
adds
the categories before the existing category specified by catname.
'Before'
, catname)
Merge categories in categorical array.
B = mergecats (A, oldcats)
merges two or more
categories specified by oldcats into a single category with the
same name as oldcats(1)
. In case of ordinal categorical
arrays, the categories listed in oldcats must be in consecutive
order. All elements of A corresponding to the categories listed in
oldcats are re-indexed to correspond to oldcats(1)
in
B.
B = mergecats (A, oldcats, newcat)
merges
the categories listed in oldcats into a single new category named
as specififed by newcat.
Remove categories from categorical array.
B = removecats (A)
removes all unused categories from
categorical array A. The output categorical array B has the
same size and values as A, but potentially fewer categories.
B = removecats (A, oldcats)
removes the
categories specified by oldcats. The elements of B that
correspond to the removed categories are undefined.
Rename categories in categorical array.
Renames some or all of the categories in obj, without changing any of its values.
Reorder categories in categorical array.
B = reordercats (A)
reorders the categories of A
in alphanumeric order.
B = reordercats (A, neworder)
reorders the
categories of A according to the order specified by neworder,
which must be a cell array of character vectors or a string array with
the same set of values as the existing categories in A.
Set categories in categorical array.
B = setcats (A, newcats)
sets categories in a
categorical array according to the elements of the imput array and the
categories specified by newcats.
Combine categorical arrays.
C = times (A, B)
is the equivalent of the syntax
A .* B
and returns a categorical array whose
categories are the Cartesian product of the categories in A and
B and each element is indexed to a new category which is the
combination of the categories of the corresponding elements in A
and B.
A and B must be of common size or scalars.
categorical.eq
is not documented.
categorical.ge
is not documented.
categorical.gt
is not documented.
categorical.le
is not documented.
categorical.lt
is not documented.
categorical.ne
is not documented.
categorical.sort
is not documented.
categorical.sortrows
is not documented.
categorical.sortrows
is not documented.
categorical.intersect
is not documented.
categorical.setdiff
is not documented.
categorical.setxor
is not documented.
categorical.union
is not documented.