Previous Up Next

20.1.12  Frequencies

The frequency of a number in a list is the fraction of the list equal to the number. The frequencies or frequences command finds the frequencies of the numbers in a list.

Example

frequencies([1,2,1,1,2,1,2,4,3,3])
     
⎡
⎢
⎢
⎢
⎣
10.4
20.3
30.2
40.1
⎤
⎥
⎥
⎥
⎦
          

You can use this, for example, to simulate flipping a fair coin and seeing how many times each side appears; to flip a coin 1000 times, for example:

frequencies([rand(2)$(k=1..1000)])
     
⎡
⎢
⎣
00.484
10.516
⎤
⎥
⎦
          

(See Section 20.3.2 for information on rand.)


Previous Up Next