使用基R:
u <- as.vector(unique(df$Receipt_no))
as.list(sapply(u, function(x) paste0(x, ", ", paste0(subset(df$Product, df$Receipt_no==x), collapse = ", "))))
# $A1
# [1] "A1, Apple, Banana, Orange"
# $A2
# [1] "A2, Pineapple, Jackfruit"
# $A3
# [1] "A3, Cola, Tea"
DATA
df <- structure(list(Receipt_no = structure(c(1L, 1L, 1L, 2L, 2L, 3L,
3L), .Label = c("A1", "A2", "A3"), class = "factor"), Product = structure(c(1L,
2L, 5L, 6L, 4L, 3L, 7L), .Label = c("Apple", "Banana", "Cola",
"Jackfruit", "Orange", "Pineapple", "Tea"), class = "factor")), .Names = c("Receipt_no",
"Product"), class = "data.frame", row.names = c(NA, -7L))
請問您是否可以回覆以下任何內容適合您? – mtoto
Soto的回覆很好 – Nithish