问题描述
我最近开始使用R,但我认为我不太了解hist()
函数.我目前正在使用长度为296的数字矢量,我想将其分为10个相等的间隔,并生成频率直方图以查看哪些值落入每个间隔.我以为hist(dataset, breaks = 10)
可以完成工作,但是它将其分为12个间隔.我显然误解了breaks
的作用.
I've recently started using R and I don't think I'm understanding the hist()
function well. I'm currently working with a numeric vector of length 296, and I'd like to divide it up into 10 equal intervals, and produce a frequency histogram to see which values fall into each interval. I thought hist(dataset, breaks = 10)
would do the job, but it's dividing it into 12 intervals instead. I obviously misunderstood what breaks
does.
如果我想在直方图中将数据分为10个间隔,该怎么做?谢谢.
If I want to divide up my data into 10 intervals in my histogram, how should I go about doing that? Thank you.
推荐答案
按照文档,如果您给breaks
参数指定一个数字,则该参数将被视为建议,因为它会提供漂亮断点.如果要强制将其设置为10个等距的垃圾箱,最简单的方法可能是以下操作,
As per the documentation, if you give the breaks
argument a single number, it is treated as a suggestion as it gives pretty breakpoints. If you want to force it to be 10 equally spaced bins, the easiest is probably the following,
x = rnorm(50)
hist(x, breaks = seq(min(x), max(x), length.out = 11))
长度应为n+1
,其中n
是所需箱的数量.
The length should be n+1
where n
is the number of desired bins.
这篇关于了解R中的hist()和break间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!