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
  • 25,090
  • 5
  • 44
  • 85
Brad
  • 451
  • 3
  • 17

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
  • 789,025
  • 32
  • 460
  • 575