table

Methods

Method Reference: table.issortedrows

table: TF = issortedrows (tblA)
table: TF = issortedrows (tblA, 'RowNames')
table: TF = issortedrows (tblA, rowDimName)
table: TF = issortedrows (tblA, vars)
table: TF = issortedrows (tblA, …, direction)
table: TF = issortedrows (…, Name, Value)

Check if table rows are sorted accordingly.

TF = issortedrows (tblA) determines if the rows in tblA are sorted in ascending order based on the values in the first variable or subsequent variables if elements of the former are repeated. TF is a logical scalar and it is true when tblA == sortrows (tblA) or false otherwise.

TF = issortedrows (tblA, 'RowNames') determines if the rows in tblA are sorted according to its row names. TF is true when tblA == sortrows (tblA, 'RowNames') or false otherwise. If tblA does not have row names, i.e. tblA.Properties.RowNames is empty, then TF is true.

TF = issortedrows (tblA, rowDimName) determines if the rows in table tblA are sorted along the first dimension, rowDimName, which is the equivalent to the previous syntax, i.e. according to its row names. For this syntax to work, rowDimName must match the first element in tblA.Properties.DimensionNames, otherwise rowDimName is considered a variable name, as in the following syntax. TF is true when tblA == sortrows (tblA, rowDimName) or false otherwise. If tblA does not have row names, i.e. tblA.Properties.RowNames is empty, then TF is true.

TF = issortedrows (tblA, vars) determines if the rows in tblA are sorted by the elements in the variables specified by vars, which can be a character vector (for a single variable) or a cell array of character vectors or a string array (specifying a single or multiple variables). If tblA has row names, then vars can include the row names. Alternatively, vars can be a logical vector or a numeric vector of real integers indexing the desired variables. Positive integers specify an ascending order, whereas negative integers specify a descending order for the referenced variables. You can also index all available variables in tblA by passing a semicolon character argument. This Octave-specific syntax facilitates the use of the direction input argument when no particular variable needs to be selected to sort on. Additionally, vars can be a vartype object used to create a subscript that selects variables of a specified type.

TF = issortedrows (tblA, …, direction) determines if the rows in tblA are sorted in the order specified by direction for any of the previous syntaxes. direction can be 'ascend' or 'descend', which is applied to all specified variables or row names that sortrows operates on. direction can also be a cell array of character vectors, whose elements are 'ascend' and 'descend', where each element corresponds to the specified variables and/or row names used for sorting the table. The order specified by direction always takes precedence over the order defined by a numerical vector of integers in vars. direction must always be the 3rd input argument. If you want to omit passing selected variables and allow sortrows to work on consecutive variables until all ties are resolved, then you can leave the second input argument empty, as in sortrows (tblA, {[]}, direction) or pass a colon argument for vars as in sortrows (tblA, {':'}, direction).

TF = issortedrows (…, Name, Value) determines if the rows in tblA are sorted according the additional parameters specifying the sorting of rows of a table with the following Name-Value paired arguments.

  • 'MissingPlacement' specifies the placement of missing values with one of the following options: 'auto' places the missing elements at the bottom for ascending order and at the top for descending order; 'first' places missing elements at the top; 'last' places missing elements at the bottom.
  • 'ComparisonMethod' specifies the element comparison method with one of the following options: 'auto' sorts rows using the real part for real numbers and the magnitude for complex numbers; 'real' sorts rows using the real part for both real and complex numbers; 'abs' sorts rows using the magnitude for both real and complex numbers. For complex numbers with equal magnitude, the phase angle in the interval (-π, π] is further used to break ties.

Source Code: table

Example: 1

issortedrows tests whether the rows are already in sorted order, using the same key/direction syntax as sortrows — handy to skip a needless sort.

 T = table ([1; 3; 2], [10; 20; 30], 'VariableNames', {'Age', 'Height'})
T =
  3x2 table

    Age    Height    
    ___    ______    

      1        10    
      3        20    
      2        30
 issortedrows (T, 'Age')
ans = 0

The Height column is ascending, so a check on that variable succeeds.

 issortedrows (T, 'Height')
ans = 1

Directions are checked too: this asks whether Age is descending.

 issortedrows (T, 'Age', 'descend')
ans = 0