# count() Function & Examples

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

## count

#### count(x)

Try it yourself:

```calculio
a = [1, 2; 3, 4; 5, 6]
count(a)
size(a)
count("hello world")
```

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

---

## Count values in arrays and matrices

**count(x)** returns how many elements occur in x. It is a compact way to measure the length of a vector or the total number of entries in a matrix, and it often belongs at the start of data-cleaning and summary calculations.

## What is counted

For `count([4, 8, 15])`, the result is 3. For a matrix, count measures its entries rather than only its rows. Use [size](https://calcul.io/function/size/index.md) when you need each dimension, such as rows and columns, and [leafCount](https://calcul.io/function/leafCount/index.md) when working with nested expression structures rather than ordinary data.

## Useful workflows

Count filtered results to answer questions like “how many readings passed the threshold?” First create the selected values with [filter](https://calcul.io/function/filter/index.md), then apply count. It also helps validate that two aligned series have the same number of observations before using [corr](https://calcul.io/function/corr/index.md) or calculating a statistic such as [mean](https://calcul.io/function/mean/index.md).

## Input caveats

Count does not sum values and does not count only truthy values; it reports elements in the supplied collection. Use [sum](https://calcul.io/function/sum/index.md) for totals, and prepare the collection before counting if missing values need exclusion. A scalar is not a list of observations, so choose an array or matrix when the question is about a collection. For deduplicated values, combine a suitable distinct-set operation with count rather than assuming repeated entries disappear automatically.

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