[R] dividing vectors into bins with equal widths

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Tue Nov 14 14:20:19 CET 2006


Hi Daniel,

Make sure to include working code and list all needed packages. I couldn't run your code on my machine.

If you want equal data points in each class, then you could take every n point from the sorted vector. This example generates the breakpoints to divide a vector in 10 parts.

> x <- floor(rnorm(100) * 10)
> x
  [1]  -2   9 -12   3  11   7   6  -4 -16  -1   1  -7  -7   7   4  -4  -7  13   1   9  10   1  11  19 -19  -3  12  -6   5  -7   1 -13 -15
 [34]  11  -8  -2 -13  10   6   8  15   4   0  -4  12   5  -2  -3   9 -17  -5   9   0   3   7   7   8 -14 -12  -4  -4 -24  -4   4  16   5
 [67]   6  -8  -7 -14  -8  -4  -9  18  -2  11  11 -16  -2   2  -1  -8  10   2  21  -9   1  -3 -17  -4  10  -5 -14   7 -13  -6   8  -4  -2
[100]  -2
> NBreaks <- 10
> sort(x)[NBreaks * (1:(length(x) / NBreaks - 1))]
[1] -14  -8  -5  -3  -1   2   6   9  11


Cheers,

Thierry

----------------------------------------------------------------------------

ir. Thierry Onkelinx

Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest

Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance

Gaverstraat 4

9500 Geraardsbergen

Belgium

tel. + 32 54/436 185

Thierry.Onkelinx op inbo.be

www.inbo.be 

 

Do not put your faith in what statistics say until you have carefully considered what they do not say.  ~William W. Watt

A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney

-----Oorspronkelijk bericht-----
Van: r-help-bounces op stat.math.ethz.ch [mailto:r-help-bounces op stat.math.ethz.ch] Namens W. Daniel Kissling
Verzonden: dinsdag 14 november 2006 13:52
Aan: r-help op stat.math.ethz.ch
CC: kissling op uni-mainz.de
Onderwerp: [R] dividing vectors into bins with equal widths

Hi R-users,

I am trying to divide a vector (say X) into equal frequency bins. If one uses the hist() 
function, then a histogram is plotted, but with bins of equal widths, and not with bins 
having the same number of data points.

I have then tried the histogram() function as follows:

histogram(X, nint=10, breaks=NULL, equal.widths=F)

This works as I want. However, I can't extract which points are in which bin, or where 
the breakpoints are made.

Can anybody help?

Thanks 
Daniel

--------------------------------------------------------------------
W. Daniel Kissling
Institut für Zoologie, Abteilung Ökologie
Johannes Gutenberg-Universität Mainz
D-55099 Mainz, Germany
E-mail: kissling op uni-mainz.de

______________________________________________
R-help op stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list