[R] hist function to give each cell equal area

Roger Bivand Roger.Bivand at nhh.no
Fri Jan 7 13:17:31 CET 2005


On Fri, 7 Jan 2005, Dan Bolser wrote:

> On Fri, 7 Jan 2005, BXC (Bendix Carstensen) wrote:
> 
> >how about:
> >
> >x <- rnorm(400)
> >nbin<-7
> >hist(x,breaks=quantile(x,prob=seq(0,1,length=nbin+1)))
> 
> Thanks for the replies! Quantiles are my new friend. Its true the example
> I gave was a bit tricky, I just wanted to get the idea over.
> 
> One thing that is slightly confusing (probably a slight syntax thing),
> combining the above with the reply from Peter Dalgaard...
> 
> nbin<-10
> x <- rnorm(400)
> hist(x,breaks=quantile(x,prob=seq(0,1,length=nbin+1)))
> 
> y <- table(cut(x,breaks=quantile(x,seq(0,1,length=nbin+1))))
> 
> > y
> [1] 399
> 
> I only get 399 counts out, and I put 400 counts in?

> y <- table(cut(x,breaks=quantile(x,seq(0,1,length=nbin+1)), 
+    include.lowest = TRUE))

It's the include.lowest= argument to cut()

> 
> Cheers,
> Dan.
> 
> >
> >Bendix Carstensen
> >----------------------
> >Bendix Carstensen
> >Senior Statistician
> >Steno Diabetes Center
> >Niels Steensens Vej 2
> >DK-2820 Gentofte
> >Denmark
> >tel: +45 44 43 87 38
> >mob: +45 30 75 87 38
> >fax: +45 44 43 07 06
> >bxc at steno.dk
> >www.biostat.ku.dk/~bxc
> >----------------------
> >
> >
> >
> >> -----Original Message-----
> >> From: r-help-bounces at stat.math.ethz.ch 
> >> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Dan Bolser
> >> Sent: Friday, January 07, 2005 11:21 AM
> >> To: R mailing list
> >> Subject: [R] hist function to give each cell equal area
> >> 
> >> 
> >> 
> >> Hi,
> >> 
> >> I want to use hist with non-equi-spaced breaks, picked such 
> >> that the fraction of the data points falling in the cells 
> >> (defined by 'breaks') is 
> >> roughly equal accross all cells.
> >> 
> >> Is there such a function that will automatically try to 
> >> determine the breaks to fullfill this requirement?
> >> 
> >> Something like..
> >> 
> >> hist( x, br = magic_function_to_pick_breaks())
> >> 
> >> 
> >> For example, if x looked like this...
> >> 
> >> x <- c( 1:5, 10+1:5, 100+1:5 )
> >> 
> >> the breaks would define cells like this 
> >> 
> >> hist(x,breaks=c(0,5,15,105))
> >> 
> >> Is there such a function?
> >> 
> >> ______________________________________________
> >> R-help at 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
> >> 
> >
> 
> ______________________________________________
> R-help at 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
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no




More information about the R-help mailing list