How can I get a histogram/summary stats if I have a table with counts? [duplicate]

霸气de小男生 提交于 2019-12-31 07:36:44

问题


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

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?


回答1:


Unwrapping the data:

unwrapped <- rep(value, numObs)

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)



回答2:


A possible solution:

with(df, rep(value, numObs))

where df is the name of your data.frame.



来源:https://stackoverflow.com/questions/23839177/how-can-i-get-a-histogram-summary-stats-if-i-have-a-table-with-counts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!