[R] hist densities

2008-04-25 Thread Sarah Hardy
This is a reply to Luke Spadavecchia's question about hist densities. If you want to construct a histogram where the bar heights are the percentage of observations in the intervals you can use this code: x<-rnorm(n=5000,mean=1.5,sd=0.25) h<-hist(x) h$density<-h$counts/sum(h$counts) plot(

Re: [R] hist densities

2008-03-21 Thread Prof Brian Ripley
On Fri, 21 Mar 2008, Luke Spadavecchia wrote: > Hi there, > > I was wondering why > > x<-rnorm(n=5000,mean=1.5,sd=0.25) > h<-hist(x) > sum(h$density) > > [1] 10 > > I thought the integral of the histogram should be one? These seems > strange to me, or am I being silly... The integral is not a sum

[R] hist densities

2008-03-21 Thread Luke Spadavecchia
Hi there, I was wondering why x<-rnorm(n=5000,mean=1.5,sd=0.25) h<-hist(x) sum(h$density) [1] 10 I thought the integral of the histogram should be one? These seems strange to me, or am I being silly... Regards Luke Spadavecchia PS. I'm using R 2.5.1 on Mac OSX _