了解R中的hist()和break间隔 [英] Understanding hist() and break intervals in R

查看:433
本文介绍了了解R中的hist()和break间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用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.

推荐答案

按照

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间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆