[R] Histogram
arun
smartpink111 at yahoo.com
Wed Sep 4 22:28:11 CEST 2013
Hi,
replicate(100,length(hist(10,0:10)$counts))
# [1] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
#[26] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
#[51] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
#[76] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
set.seed(56)
a1<- rnorm(100)
bins<- seq(min(a1),max(a1)+1,by=0.2)
replicate(100,length(hist(a1,breaks=bins)$counts))
# [1] 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29
#[26] 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29
#[51] 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29
#[76] 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29
#May be this is what you are looking for:
library(Rlab)
set.seed(56)
replicate(100,length(hplot(rnorm(100),nclass=10)$counts))
# [1] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
#[26] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
#[51] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
#[76] 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
A.K.
----- Original Message -----
From: philippe massicotte <pmassicotte at hotmail.com>
To: Rui Barradas <ruipbarradas at sapo.pt>
Cc: "r-help at R-project.org" <r-help at r-project.org>
Sent: Wednesday, September 4, 2013 4:02 PM
Subject: Re: [R] Histogram
Thank you everyone.
Try executing this:
replicate(100, length(hist(rnorm(100), nclass = 10)$counts))
I'm still not sure why the number of bins (classes) is not consistent.
Thank in advance.
> Date: Wed, 4 Sep 2013 20:27:36 +0100
> From: ruipbarradas at sapo.pt
> To: pmassicotte at hotmail.com
> CC: r-help at r-project.org
> Subject: Re: [R] Histogram
>
> Hello,
>
> See the arguments 'right' and 'include.lowest' of ?hist.
> To give what you want, try instead
>
> h1 <- hist(1:10, 10) # counts are 2, 1, 1, ...
> h2 <- hist(1:10, breaks = 0:10) # all counts are 1
>
>
> and see the difference between h1 and h2, components 'breaks' and 'counts'.
>
> Hope this helps,
>
> Rui Barradas
>
> Em 04-09-2013 19:34, philippe massicotte escreveu:
> > Hi everyone.
> > I'm currently translating some Matlab code into R. However, I realized that the hsit function produce different results in both languages.
> > in Matlab, hist(1:10, 10) will produce 10 bins with a count of 1 in each, but in R it will produce 9 classes with count of 2,1,1,1,1,1,1,1,1.
> > I'm a bit embarrassed to ask such question, but why R is not producing 10 classes as requested?
> > Thanks in advance,Phil
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org 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.
> >
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org 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