---
title: "sorted(on:by:)"
framework: tabulardata
role: symbol
role_heading: Instance Method
path: "tabulardata/dataframeprotocol/sorted(on:by:)"
---

# sorted(on:by:)

Generates a data frame by copying the data frame’s rows and then sorting the rows according to a column that you select by its column identifier, with a predicate.

## Declaration

```swift
func sorted<T>(on columnID: ColumnID<T>, by areInIncreasingOrder: (T, T) throws -> Bool) rethrows -> DataFrame
```

## Parameters

- `columnID`: The identifier of a column.
- `areInIncreasingOrder`: A closure that returns a Boolean that indicates whether the two elements are in increasing order.

## Discussion

Discussion note: Elements with a value of nil are less than all non-nil values.

## See Also

### Creating a Data Frame by Sorting a Column

- [sorted(on:order:)](tabulardata/dataframeprotocol/sorted(on:order:)-818u5.md)
- [sorted(on:_:order:)](tabulardata/dataframeprotocol/sorted(on:_:order:)-8d7rr.md)
- [sorted(on:_:by:)](tabulardata/dataframeprotocol/sorted(on:_:by:).md)
- [sorted(on:order:)](tabulardata/dataframeprotocol/sorted(on:order:)-5nl5c.md)
