<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 10.14.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateML",
  "identifier" : "/documentation/CreateML/MLDataTable/subscript(_:)-3opgl",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Subscript",
  "symbol" : {
    "kind" : "Instance Subscript",
    "modules" : [
      "Create ML"
    ],
    "preciseIdentifier" : "s:8CreateML11MLDataTableVyAcA0C6ColumnVySbGcip"
  },
  "title" : "subscript(_:)"
}
-->

# subscript(_:)

Creates a subset of the table by masking the rows with the given column
of Booleans.

```
subscript(mask: MLDataColumn<Bool>) -> MLDataTable { get }
```

## Parameters

`mask`

A Boolean column indicating whether rows should be kept (`true`)
or removed (`false`) in the derived table.

## Return Value

A new data table.

## Overview

Use this Boolean column–based subscript to create a new table by masking
a subset of the table rows.

![A table of book titles and genres such as “Hamlet” and “Drama” on the](images/com.apple.createml/MLDataTable-subscript(_:)-3opgl-1@2x.png)

For example, to filter the values in a data table as shown above, begin
by creating a table with the original data.

```swift
let data: [String: MLDataValueConvertible] = [
    "Title": ["Alice in Wonderland", "Hamlet", "Treasure Island", "Peter Pan"],
    "Genre": ["Fantasy", "Drama", "Adventure", "Fantasy"]
]

let table = try? MLDataTable(dictionary: data) else {
    fatalError("Invalid dictionary data")
}
```

After you create the table, use column arithmetic operators or the
[`map(_:)`](/documentation/CreateML/MLDataTable/map(_:)-92wrj) method to build a row mask. The subscript
uses the Boolean values in the row mask to determine whether to keep a
row.

```swift
// Retrieve the "Genre" column from the table.
guard let genreColumn = table["Genre", String.self] else {
    fatalError("Missing or invalid 'genre' column in table.")
}

// Create a new column of Booleans by comparing all of the values
// in `Genre` with `Fantasy` using the
// `!=(MLDataColumn<String>, String) -> MLDataColumn<Bool>` operator.
let noFantasyMask = genreColumn != "Fantasy"
```

Use `subscript(mask: MLDataColumn<Bool>)` with the Boolean column–row
mask to create a filtered table.

```swift
let noFantasyTable = table[noFantasyMask]
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)