-1

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?

Palace Chan
  • 8,845
  • 11
  • 41
  • 93
  • what output are you expecting? objects from class data.frame have a method for summary ... have you try at least summary(your_data_frame_name)? – luis_js May 23 '14 at 22:43
  • 1
    I closed the other one since in my judgement they were dups and this had a better answer. Does make one wonder about homework, though, to see two very similar questions in quick succession. I suspect many other duplicates exist. Hence my downvote for failure to search. – IRTFM May 23 '14 at 23:40

2 Answers2

2

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)
Michael Lawrence
  • 1,031
  • 5
  • 6
0

A possible solution:

with(df, rep(value, numObs))

where df is the name of your data.frame.

Davide Passaretti
  • 2,741
  • 1
  • 21
  • 32