Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting frequency values from histogram in R

I know how to draw histograms or other frequency/percentage related tables. But now I want to know, how can I get those frequency values in a table to use after the fact.

I have a massive dataset, now I draw a histogram with a set binwidth. I want to extract the frequency value (i.e. value on y-axis) that corresponds to each binwidth and save it somewhere.

Can someone please help me with this? Thank you!

like image 569
MiMi Avatar asked Oct 12 '11 13:10

MiMi


People also ask

How do you find the frequency of a histogram in R?

We can extract Frequency Counts of Histogram using hist() Function in R programming language. hist() function is used to plot a histogram out of the given data. Parameters: v: This parameter contains numerical values used in histogram.

How do you find the frequency distribution in R?

The table() method in R is used to compute the frequency counts of the variables appearing in the specified column of the dataframe. The result is returned to the form of a two-row tabular structure, where the first row indicates the value of the column and the next indicates its corresponding frequencies.


1 Answers

The hist function has a return value (an object of class histogram):

R> res <- hist(rnorm(100)) R> res $breaks [1] -4 -3 -2 -1  0  1  2  3  4  $counts [1]  1  2 17 27 34 16  2  1  $intensities [1] 0.01 0.02 0.17 0.27 0.34 0.16 0.02 0.01  $density [1] 0.01 0.02 0.17 0.27 0.34 0.16 0.02 0.01  $mids [1] -3.5 -2.5 -1.5 -0.5  0.5  1.5  2.5  3.5  $xname [1] "rnorm(100)"  $equidist [1] TRUE  attr(,"class") [1] "histogram" 
like image 185
rcs Avatar answered Oct 04 '22 02:10

rcs