【发布时间】:2018-08-02 14:50:02
【问题描述】:
您好,我有一个这样的数据框:
> dput(tst_df)
structure(list(Item = c("a", "a", "a", "a", "a", "b", "b", "b",
"b", "b"), sku = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L), .Label = c("HOU394386-411", "HOU454800-463"), class = "factor"),
ean = structure(1:10, .Label = c("8718476625642", "8718476625659",
"8718476625666", "8718476625673", "8718476625680", "8718476630066",
"8718476630073", "8718476630080", "8718476630097", "8718476630103"
), class = "factor")), .Names = c("Item", "sku", "ean"), row.names = c(NA,
-10L), class = "data.frame")
我想要的是在 sku 列上分组,并且 sku 旁边应该是属于该 SKU 的 eans。
例子:
第 1 行:
HOU394386-411 8718476625642 8718476625659 8718476625666 8718476625673 8718476625680
第 2 行:
HOU454800-463 8718476630066 8718476630073 8718476630080 8718476630097 8718476630103
如果我尝试使用 group_by 并从 dplyr 包中总结或使用 reshapes 函数转换来实现这一点,我不会得到我想要的。所有 EANS 都成为列,我只想使用属于 SKU 的 EAN。这甚至可能吗?
【问题讨论】:
标签: r group-by reshape reshape2