将整洁的小标题扩展到其原始形式

时间:2019-05-27 04:09:05

标签: r tidyverse

我有个整洁的小贴士。

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

我需要将其扩展回其原始形式。

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"))

tidy()函数具有相反的功能吗?

1 个答案:

答案 0 :(得分:1)

我们可以使用uncount中的tidyr通过将weights指定为'Count'将数据扩展为长格式

library(tidyr)
uncount(Tibble, Count)