[R] how to get variables from hist?

Anders Nielsen anielsen at math.ku.dk
Tue Nov 14 13:01:33 CET 2000


On Tue, 14 Nov 2000, Meriema Belaidouni wrote:

> hello,
> my question concerns how to get variables from hist function?
> pp is some variable
> >hist(pp)     #gives the histogram of pp
> >str(hist(pp))    #gives 4 variables  which values are for example
> $breaks  :  num[1..18] 5 10 15 20 25 ...
> $counts   :  int[1..17] 1215    19381    47721 ...
> $ intensities :  num [1..17]   0.00243    0.03876    0.09544 ...
> $mids        : num[1..17]   7.5  12.5   17.5  22.5 ...
>
> I want to  plot intensities against mids for example
> what I need is to get intensities and mids  as variables to be able to
> use plot function.
>

Try something like;

> x<-rnorm(1000)
> x.hist<-hist(x, plot=F) #now the histogram is stored in x.hist
> x.hist
$breaks
[1] -4 -3 -2 -1  0  1  2  3  4

$counts
[1]   1  24 143 333 338 137  22   2

$intensities
[1] 0.001 0.024 0.143 0.333 0.338 0.137 0.022 0.002

$mids
[1] -3.5 -2.5 -1.5 -0.5  0.5  1.5  2.5  3.5

> plot(x.hist$mids, x.hist$intensities)


(See also ?density)

Anders 
 


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list