On 09-May-08 00:12:46, David Scott wrote:
> On Thu, 8 May 2008, Roslina Zakaria wrote:
> 
>> 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) <[EMAIL PROTECTED]>
Fax-to-email: +44 (0)870 094 0861
Date: 09-May-08                                       Time: 01:26:35
------------------------------ XFMail ------------------------------

______________________________________________
R-help@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.

Reply via email to