使用聚合数据创建直方图 [英] Creating a histogram using aggregated data

查看:146
本文介绍了使用聚合数据创建直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

令人尴尬的简单问题...



我是R的新手,我似乎无法围绕这个原因。我有一个CSV文件,看起来像这样:

  Bin,Number 
1363,5
1028 ,4
1303,3
1467,1
1242,3
1415,5
..

容器大小为1,范围为1000-1500。我已经读取我的CSV文件,一切似乎都确定,但我只是不能产生一个简单的直方图。我试过简单地使用条形图,但数据不是数字排序,所以不会产生我需要的输出。使用这样的数据,我如何在R?中产生一个直方图?



一旦我有一个简单的直方图,我相信我可以玩因为 hist 函数会执行以下操作:

计数每个bin中的项目,您需要爆炸您已经计数的数据,例如通过使用 rep 。然后,您可以在结果向量上使用 hist

  ,hist(rep(x = Bin,times = Number)))


Embarrassingly simple question...

I'm new to R and I can't seem to wrap my head around this for some reason. I have a CSV file which looks something like this:

Bin,Number
1363,5
1028,4
1303,3
1467,1
1242,3
1415,5
..
.

The bin size is 1, with a range of 1000-1500. I have read my CSV file in, everything seems to be ok there, but I just cannot produce a simple histogram. I have tried simply using a barplot, but the data is not numerically ordered, so will not produce the output I need. Using data such as this, how can I produce a histogram in R?

Once I have a simple histogram, I'm sure I'll be able to play around with it and format it nicely.

解决方案

Because the hist function does the counting of items in each bin, you need to 'explode' your 'already counted' data, for example by using rep. Then you can use hist on the resulting vector.

with(df, hist(rep(x = Bin, times = Number)))

这篇关于使用聚合数据创建直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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