Re: [R] histogram

From: Ted Harding <Ted.Harding_at_manchester.ac.uk>
Date: Fri, 09 May 2008 01:26:40 +0100 (BST)
```>> Dear R-expert,
>> For histogram function, can we get the table of bin and
>> frequency like in excel, together with the histogram?
>> Therefore, we can check the number of data included.
>> Thank you so much for your attention and help.
```

>
> Easy one: just use the argument plot=FALSE and hist will produce the
> counts etc for you
>
> David Scott

Well, there's a slightly nicer way than that! (Don't forget that we're competing with Excel here ... ).

Since the value of hist() includes breakpoints and counts, you can get the plot and the table as follows:

set.seed(54321)
X <- 5*rnorm(500)
H<-hist(X) ### Here you get the histogram drawn   B<-H\$breaks ; C<-H\$counts ; k<-length(B)   cbind(From=B[1:(k-1)],To=B[2:k],Count=C) ### Here bins and frequencies

```#     From  To Count
#[1,]  -15 -10    16
#[2,]  -10  -5    69
#[3,]   -5   0   181
#[4,]    0   5   149
#[5,]    5  10    71
#[6,]   10  15    14

```

So we can indeed "get the table of bin and frequency like in excel, together with the histogram".

Best wishes to all,
Ted.

E-Mail: (Ted Harding) <Ted.Harding_at_manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861
```Date: 09-May-08                                       Time: 01:26:35
------------------------------ XFMail ------------------------------

______________________________________________
```
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. Received on Fri 09 May 2008 - 00:35:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 09 May 2008 - 01:30:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.