count

count(x)

Try it yourself:

See also:

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 when you need each dimension, such as rows and columns, and leafCount 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, then apply count. It also helps validate that two aligned series have the same number of observations before using corr or calculating a statistic such as mean.

Input caveats

Count does not sum values and does not count only truthy values; it reports elements in the supplied collection. Use sum 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