如果我有一张桌子,我可以得到一个直方图/汇总统计数据吗? [英] How can I get a histogram/summary stats if I have a table with counts?

查看:165
本文介绍了如果我有一张桌子,我可以得到一个直方图/汇总统计数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯了像 c(1,1,1,3,4)这样的观察向量,我可以看到汇总统计数据和绘图直方图等...但是现在我发现自己是同样的数据,但是采用这样的压缩格式:

I'm used to having a vector of observations like c(1,1,1,3,4) on which I can see summary statistics and plot histograms etc...but now I find myself with, the same data, but in a compressed format like this:

value, numObs
1, 3
3, 1
4, 1

当数据以 data.frame 如上所述表示时,我可以轻松地展开到矢量中或查看相同的摘要统计信息或直方图。

How can I easily "unwrap" this easily into the vector or view the same summary stats or histogram plots when the data is expressed in a data.frame as above?

推荐答案

解开数据:

unwrapped <- rep(value, numObs)

如果您对压缩表单,然后查看?barplot 来绘制它。您将首先填写零,如下所示:

If you're happy with the binning of your "compressed form" then see ?barplot for plotting it. You would want to fill the zeros first, like:

v <- numeric(max(value))
v[value] <- numObs
barplot(v)

这篇关于如果我有一张桌子,我可以得到一个直方图/汇总统计数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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