使用聚合数据创建直方图

编程入门 行业动态 更新时间:2024-10-21 11:32:27
本文介绍了使用聚合数据创建直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

我是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)))

更多推荐

使用聚合数据创建直方图

本文发布于:2023-06-13 17:35:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/686631.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:直方图   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!