如何在 R 中修改表并创建直方图表示的 bin
我对 R 有点陌生,我正在尝试 ggplot。
我有一个像这样的表:
表 http://dl.dropbox.com/ u/43697/temporary/data_frame.jpg
我想修改表格以根据不同的休息时间设置垃圾箱并记录每个垃圾箱的频率:
表 http://dl.dropbox.com/u/43697/temporary/data_frame2.jpg
我想要做的第一件事是在年份列上设置分隔符,然后转置它们以匹配 AllotmentID。
有什么想法吗?
I am a bit new to R and I was experimenting with ggplot.
I have a table like this:
table http://dl.dropbox.com/u/43697/temporary/data_frame.jpg
I would like to modify the table to set bins based on different breaks and record the frequency for each bin:
table http://dl.dropbox.com/u/43697/temporary/data_frame2.jpg
I guess the first thing to do would be to set breaks on the year columns and later transpose them to match the AllotmentID.
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有可重现的示例,也没有提示您想要使用 ggplot2 制作哪种类型的图表,我所能做的就是为您指明一个有用的工具的方向。在这种情况下,我怀疑您会想要充分利用函数
cut
,它通常是 R 中用于分箱的首选工具。cut
将返回一个因子,您可能希望将其传递给table
来计算每个“bin”中的观测值数量。编辑
这是一个非常简单的例子。您需要对其进行修改,以使休息区和垃圾箱按照您希望的方式工作:
Without a reproducible example, and no hint of what sort of graph you'd like to make using
ggplot2
, all I can do is point you in the direction of a useful tool. In this case I suspect you will want to make good use of the functioncut
, which is usually the go-to tool in R for binning.cut
will return a factor, which you will likely want to pass totable
to count the number of observations in each "bin".EDIT
Here's a very bare bones example. You will want to tinker with it to make the breaks and bins work out the way you want them to: