1

I have a tidy tibble.

Tibble <- data.frame(Doc_ID = c(1, 9, 9, 67),
                     Compartment = c("Car", "Truck", "Bus", "Plane"),
                     Count = c(3, 2, 1, 5))

I need to extend it back to its original form.

Result <- data.frame(Doc_ID = c(1,1,1,9,9,9,67,67,67,67,67), 
                     Compartment = c("Car","Car","Car","Truck","Truck","Bus",
                                     "Plane","Plane","Plane","Plane","Plane"))

Does the tidy() function have an opposite function?

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
Brad
  • 580
  • 4
  • 19

1 Answers1

1

We can use uncount from tidyr to expand the data to long format by specifying the weights as 'Count'

library(tidyr)
uncount(Tibble, Count)
akrun
  • 874,273
  • 37
  • 540
  • 662