从R中的直方图获取频率值 [英] Getting frequency values from histogram in R
本文介绍了从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.
我有一个庞大的数据集,现在我绘制了一个设置了binwidth的直方图.我想提取与每个binwidth对应的频率值(即y轴上的值)并将其保存在某处.
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!
推荐答案
hist
函数具有返回值(类histogram
的对象):
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"
这篇关于从R中的直方图获取频率值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文