# subset() Function & Examples

Use the subset() matrix function in Calcul.io. Review its syntax, edit working examples, understand the result, and explore related math functions.

## subset

#### value(index)

#### value(index) = replacement

#### subset(value, [index])

#### subset(value, [index], replacement)

Try it yourself:

```calculio
d = [1, 2; 3, 4]
e = []
e[1, 1:2] = [5, 6]
e[2, :] = [7, 8]
f = d * e
f[2, 1]
f[:, 1]
f[[1,2], [1,3]] = [9, 10; 11, 12]
f
```

[concat](https://calcul.io/function/concat/index.md)

[det](https://calcul.io/function/det/index.md)

[diag](https://calcul.io/function/diag/index.md)

[identity](https://calcul.io/function/identity/index.md)

[inv](https://calcul.io/function/inv/index.md)

[ones](https://calcul.io/function/ones/index.md)

[range](https://calcul.io/function/range/index.md)

[size](https://calcul.io/function/size/index.md)

[squeeze](https://calcul.io/function/squeeze/index.md)

[trace](https://calcul.io/function/trace/index.md)

[transpose](https://calcul.io/function/transpose/index.md)

[zeros](https://calcul.io/function/zeros/index.md)

---

## subset(): Selecting Part of a Collection

**subset()** extracts or updates a selected portion of an array, matrix, or object using indexes or ranges. It is useful for slicing data, choosing columns, and controlled replacement.

## Index safely

Confirm dimensions with [size()](https://calcul.io/function/size/index.md) and verify index conventions before selecting. Use [row()](https://calcul.io/function/row/index.md) or [column()](https://calcul.io/function/column/index.md) for simple matrix slices, and [range()](https://calcul.io/function/range/index.md) to build an index sequence.

When modifying a subset, ensure replacement values have compatible shape. Use [clone()](https://calcul.io/function/clone/index.md) first when the original data should remain available.

[All functions](https://calcul.io/functions/index.md)
