Previous Up Next

7.1.8  Classes: classes

The classes command can be used to groups a collection of numbers into intervals; the result will be a list where each element is an interval a..b followed by how many of the numbers are in the interval [a,b). The collection of numbers can be given as a list or matrix.

If L is a collection of numbers, a and b are numbers, then classes(L,a,b) will return the list [[a..a+b,n1],[a+b..a+2b,n2],...] where each number in L is in one of the intervals [a+kb, a+(k+1)b) and nk is how many numbers from L are in the corresponding interval. For example,

classes([0,0.5,1,1.5,2,2.5,3,3.5,4],0,2)

will return

[[0.0 .. 2.0,4],[2.0 .. 4.0,4],[4.0 .. 6.0,1]]

while

classes([0,0.5,1,1.5,2,2.5,3,3.5,4],-1,2)

will return

[[(-1.0) .. 1.0,2],[1.0 .. 3.0,4],[3.0 .. 5.0,3]]

If the numbers a and b are omitted, they will default to the configurable values of class_min and class_size, which default to 0 and 1.

Another way to split the list L into intervals is by making the third argument the midpoints of the desired intervals. For example, if you enter

classes([0,0.5,1,1.5,2,2.5,3,3.5,4],1,[1,3,5])

you will get

[[0.0..2.0,4],[2.0..4.0,4],[4.0..6.0,1]]

Finally, you can simply state the intervals that you want to use by giving them as a list for the second argument. In this case, not every number in the list is necessarily in one of the intervals. If you enter

classes([0,0.5,1,1.5,2,2.5,3,3.5,4],[1..3,3..6])

you will get

[[1 .. 3,4],[3 .. 6,3]]

Previous Up Next