问题
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