[R] Re-binning histogram data

Petr Pikal petr.pikal at precheza.cz
Thu Jun 8 15:17:29 CEST 2006



On 8 Jun 2006 at 11:35, Justin Ashmall wrote:

Date sent:      	Thu, 8 Jun 2006 11:35:46 +0100 (BST)
From:           	Justin Ashmall <ja at space.mit.edu>
To:             	Petr Pikal <petr.pikal at precheza.cz>
Copies to:      	r-help at stat.math.ethz.ch
Subject:        	Re: [R] Re-binning histogram data

> 
> Thanks for the reply Petr,
> 
> It looks to me that truehist() needs a vector of data just like
> hist()? Whereas I have histogram-style input data? Am I missing
> something?

Well, maybe you could use barplot. Or as you suggested recreate the 
original vector and call hist or truehist with other bins.

> hhh<-hist(rnorm(1000))
> barplot(tapply(hhh$counts, c(rep(1:7,each=2),7), sum))
> tapply(hhh$mids, c(rep(1:7,each=2),7), mean)
    1     2     3     4     5     6     7 
-3.00 -2.00 -1.00  0.00  1.00  2.00  3.25 
> hhh1<-rep(hhh$mids,hhh$counts)
> plot(hhh, freq=F)
> lines(density(hhh1))
>

HTH
Petr






> 
> Cheers,
> 
> Justin
> 
> 
> 
> On Thu, 8 Jun 2006, Petr Pikal wrote:
> 
> > Hi
> >
> > try truehist from MASS package and look for argument breaks or h.
> >
> > HTH
> > Petr
> >
> >
> >
> >
> > On 8 Jun 2006 at 10:46, Justin Ashmall wrote:
> >
> > Date sent:      	Thu, 8 Jun 2006 10:46:19 +0100 (BST)
> > From:           	Justin Ashmall <ja at space.mit.edu>
> > To:             	r-help at stat.math.ethz.ch
> > Subject:        	[R] Re-binning histogram data
> >
> >> Hi,
> >>
> >> Short Version:
> >> Is there a function to re-bin a histogram to new, broader bins?
> >>
> >> Long version: I'm trying to create a histogram, however my
> >> input-data is itself in the form of a fine-grained histogram, i.e.
> >> numbers of counts in regular one-second bins. I want to produce a
> >> histogram of, say, 10-minute bins (though possibly irregular bins
> >> also).
> >>
> >> I suppose I could re-create a data set as expected by the hist()
> >> function (i.e. if time t=3600 has 6 counts, add six entries of 3600
> >> to a list) however this seems neither elegant nor efficient (though
> >> I'd be pleased to be mistaken!). I could then re-create a histogram
> >> as normal.
> >>
> >> I guessing there's a better solution however! Apologies if this is
> >> a basic question - I'm rather new to R and trying to get up to
> >> speed.
> >>
> >> Regards,
> >>
> >> Justin
> >>
> >> ______________________________________________
> >> 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
> >
> > Petr Pikal
> > petr.pikal at precheza.cz
> >
> >
> 
> ______________________________________________
> 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

Petr Pikal
petr.pikal at precheza.cz



More information about the R-help mailing list