Re: histogram
- To: mathgroup at smc.vnet.net
- Subject: [mg2085] Re: [mg2058] histogram
- From: Peder Thusgaard Ruhoff <ptk at imada.ou.dk>
- Date: Fri, 29 Sep 1995 01:13:17 -0400
On Sat, 23 Sep 1995, Michael Probst <michael.probst at uibk.ac.at> wrote:
> Hi !
> I have a rather simple mma - question:
> What is the best (fastest) way to generate histograms ?
> That is: I have a list of data and I want to fill the data
> into another list which elements are zero at the beginning
> and are incramanted by one if the data is in the interval
> corresponding to the respective element of the second list
> which is just the histogram.
> I can use a Do[] but this seems clumsy:
> hist={0,0,0, .... };
> Do[
> ind=myindexfunction[data[[i]]]; hist[[ind]]=hist[[ind]]+1,
> {i,1,Length[data]}]
>
> Thanks a lot !
> Michael
>
> michael.probst at uibk.ac.at
>
>
>
Dear Michael,
I suggest you take a look at the package /Statistics/DataManipulation.m.
If you can turn your indexfunction into a list of cutoffs the following
should work in your application
====
In[1]:= Needs["Statistics`DataManipulation`"]
In[2]:= data = Table[Random[],{30}];
In[3]:= RangeCounts[data, {0.25, 0.5, 0.75}]
Out[3]= {4, 12, 8, 6}
In[4]:= ?RangeCounts
RangeCounts[data, {c1, c2, ...}] gives a list of the number of elements in
data that lie between successive cutoffs. RangeCounts[{{x1,y1}, {x2,y2},
...}, {xc1, xc2, ...}, {yc1, yc2, ...}] gives an array of range counts.
===
Best wishes,
Peder
------------------------------------------------------------------------------
Peder Thusgaard Ruhoff Phone: (+45) 66 15 86 96, ext. 2411
Dept. of Mathematics and Computer Science Fax: (+45) 65 93 26 91
Odense University, Campusvej 55 Email: ptk at imada.ou.dk
DK-5230 Odense M, DENMARK