<tally>

How many times each category appears in a list

<tally> is a General Operator component that renders how many times each category appears among its arguments: a list of counts, one per category. Where <count> reports how many values there are in total, <tally> reports how many there are of each kind.

Attributes and Properties

Attributes for <tally>

Highlighted (3)
asList

boolean. Default value: true. Whether to render the items separated by commas (true) or with no separator (false).

[ _componentListWithSelectableType ]. The categories to count, in the order the counts are reported. Omit to count the distinct values present, in sorted order.

keyword. Component type to interpret bare string children as. Omit it and they are read as what they look like: every piece naming a number makes the list numeric, anything else makes it text. Also overrides how categories is read, which is otherwise text.

ValueDescription
numberRead bare strings as numbers, ordered by value.
mathRead bare strings as math expressions, ordered by value.
textRead bare strings as text, ordered alphabetically.
booleanRead bare strings as booleans, ordered with false before true.
Other (5)
avoidScientificNotation

Whether to render numbers in full decimal form rather than scientific notation.

displayDecimals

Number of decimal places to display when rendering this number.

displayDigits

Number of significant digits to display when rendering this number.

displaySmallAsZero

Threshold below which numbers are displayed as zero.

padZeros

Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.

Common to all components (9)
copy

reference. Create an independent copy of another component by reference. Enter a references a $name.

disabled

boolean. Default value: false. Whether this component is disabled and cannot be interacted with.

extend

reference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.

fixed

Default value: false. Whether this component's value is fixed and cannot be modified.

fixLocation

boolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

hide

boolean. Default value: false. Whether to hide this component from the rendered output.

isResponse

boolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.

name

text. The name used to reference this component from elsewhere in the document.

styleNumber

integer. Default value: 1. The style number used to select this component's visual styling from the available style definitions.

Properties for <tally name="t">

Highlighted (1)

The categories the counts are counts of, in the same order.

Common to all components (4)
$t.doenetML

text. The DoenetML source code that produced this component.

$t.hide

boolean. Whether to hide this component from the rendered output.

$t.isResponse

boolean. Whether this component is treated as a response for the purposes of assessment.

$t.styleNumber

integer. The style number used to select this component's visual styling from the available style definitions.

Examples

Example: counting the values that are there

With no categories attribute, the categories are whatever distinct values turned up, in sorted order.


Example: counting a simulation

Three tags do the whole simulation: <cumulativeSum> accumulates the subpopulation sizes, <searchSorted> maps every draw onto the subpopulation it landed in, and <tally> counts them. Because every draw lands in exactly one subpopulation, the counts always sum to the number of samples.


Example: values outside the declared categories

A value matching none of the declared categories is not counted anywhere, so the counts do not sum to the number of values. This occurrence is reported as an informational message.

Attribute Examples

Attribute Example: categories

Declaring the categories keeps a slot for the ones nothing matched — 2 and 4 here — so the counts stay lined up with the faces they are counts of. Left to infer its own categories, <tally> would report only the four values that actually appeared.


Attribute Example: type

Bare strings are read as what they look like, so 007 and 008 count as the numbers 7 and 8, and the leading zeros are gone from the categories. type="text" keeps a numeral that is a label rather than a quantity — a jersey number, a ZIP code, a room number — whole.

type="math" is for the other direction. Neither 2x nor 2*x is a number, so both are read as text and compared letter by letter, which makes them two categories. Read as maths they are the same expression, and the three values are one category counted three times.


Property Examples

Property Example: categories

The categories a <tally> inferred are readable back, so a chart or a table is driven off the same component that did the counting.