Wednesday, 27 June 2012

Statistics

If you have a lot of data, and you need to know how many occurrences there are (i.e. you need statistic), it's very easy create a function to elaborate it. Look at this:
  tally: func [b [block!] /local c t v n] [
        c: sort copy b
        t: copy []
        while [not tail? c] [
            v: first c
            n: 0
            while [all [not tail? c   v = first c]] [
                n: n + 1
                c: next c
            ]
            append/only t reduce [v n]
        ]
        t
    ]


Now you can analyze all your data, look the example:


>> tally [$4 22 $4 $4 22 12:30 "hello" 12:30 ]
== [[22 2] [$4.00 3] [12:30 2] ["hello" 1]]


tally function returns you a block with the data and how many occurrences of that data in the series.

1 comment: