CUSTOMER DATE FEATURE
1 202001 A
1 202001 B
1 202002 A
2 202001 C
2 202002 A
2 202002 B
2 202002 C
I have a dataset like above and I want to get FEATUREs at each time point for each CUSTOMER like below:
CUSTOMER DATE FEATURE ALL_FEATURES
1 202001 A A,B
1 202001 B A,B
1 202002 A A
2 202001 C C
2 202002 A A,B,C
2 202002 B A,B,C
2 202002 C A,B,C
I tried dcast function like dcast(df, CUSTOMER, DATE~FEATURE) to separate FEATUREs, but then the situation is too complicated to finish:there are 9 possibilities to finish it using ifelse.
How can I finish it in a simple way? Thanks.