我有个整洁的小贴士。
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()
函数具有相反的功能吗?
答案 0 :(得分:1)
我们可以使用uncount
中的tidyr
通过将weights
指定为'Count'将数据扩展为长格式
library(tidyr)
uncount(Tibble, Count)