# Revision history [back]

If your numbers are ALL representable exactly as an R integer or float, R allows you to be lazy...

Let's be lazy :

sage: r.help("hist")

hist package:graphics R Documentation

Histograms

Description:

 The generic function ‘hist’ computes a histogram of the given data
values.  If ‘plot = TRUE’, the resulting object of class
‘"histogram"’ is plotted by ‘plot.histogram’, before it is
returned.


Usage:

 hist(x, ...)


(I abbreviated the screeenfuls of help...).

You may also want to plot yourself : R may regroup your results in more-or-less comparable bins, which mau or may not be what you want. This might come handy :

sage: results=[randint(-5,5) for i in range(100)] # Simulated results...
sage: H=r.table(results).sage() # Guarantees one count per distinct value in result.
## A mouthful, to be programmed.
sage: P=map(lambda a,b:[a,b], H.get("_Dimnames").get('DATA').values()[0],H.get('DATA'))
sage: P

[['-5', 12],
['-4', 12],
['-3', 12],
['-2', 15],
['-1', 11],
['0', 7],
['1', 10],
['2', 6],
['3', 4],
['4', 5],
['5', 6]]


points(P) is a first rough approximation of the graph you seek. Now, if you insist on a barchart,R may have some interesting possibilities...

Now, if your numbers are not representable exactly in R, I'd look for a Python library able to build a B-tree, whose nodes would store a tuple (key,number of occurrences). I don't have any idea right now, but I'd be surprised if such a library didn't exist. That would be in O(n*log(n))

HTH,

EDIT : Thierry's answer is _much_ better than mine, and is even _lazier_.

I'll leave my answer as a memento : _"Lazy" doesn't mean lazy enough to not look at Python's library documentation..._

If your numbers are ALL representable exactly as an R integer or float, R allows you to be lazy...

Let's be lazy :

sage: r.help("hist")

hist package:graphics R Documentation

Histograms

Description:

 The generic function ‘hist’ computes a histogram of the given data
values.  If ‘plot = TRUE’, the resulting object of class
‘"histogram"’ is plotted by ‘plot.histogram’, before it is
returned.


Usage:

 hist(x, ...)


(I abbreviated the screeenfuls of help...).

You may also want to plot yourself : R may regroup your results in more-or-less comparable bins, which mau or may not be what you want. This might come handy :

sage: results=[randint(-5,5) for i in range(100)] # Simulated results...
sage: H=r.table(results).sage() # Guarantees one count per distinct value in result.
## A mouthful, to be programmed.
sage: P=map(lambda a,b:[a,b], H.get("_Dimnames").get('DATA').values()[0],H.get('DATA'))
sage: P

[['-5', 12],
['-4', 12],
['-3', 12],
['-2', 15],
['-1', 11],
['0', 7],
['1', 10],
['2', 6],
['3', 4],
['4', 5],
['5', 6]]


points(P) is a first rough approximation of the graph you seek. Now, if you insist on a barchart,R may have some interesting possibilities...

Now, if your numbers are not representable exactly in R, I'd look for a Python library able to build a B-tree, whose nodes would store a tuple (key,number of occurrences). I don't have any idea right now, but I'd be surprised if such a library didn't exist. That would be in O(n*log(n))

HTH,