Одна базовая опция R использует ave
, например,
df <- within(df,ALL_FEATURES <- ave(FEATURE,CUSTOMER,DATE,FUN = list))
или
df <- within(df,ALL_FEATURES <- ave(FEATURE,CUSTOMER,DATE,FUN = toString))
, так что
> df
CUSTOMER DATE FEATURE ALL_FEATURES
1 1 202001 A A, B
2 1 202001 B A, B
3 1 202002 A A
4 2 202001 C C
5 2 202002 A A, B, C
6 2 202002 B A, B, C
7 2 202002 C A, B, C
DATA
df <- structure(list(CUSTOMER = c(1L, 1L, 1L, 2L, 2L, 2L, 2L), DATE = c(202001L,
202001L, 202002L, 202001L, 202002L, 202002L, 202002L), FEATURE = c("A",
"B", "A", "C", "A", "B", "C")), class = "data.frame", row.names = c(NA,
-7L))