Aggregating strings using tostring and counting them in r
问题 I have following dataframe got after applying dplyr code Final_df<- df %>% group_by(clientID,month) %>% summarise(test=toString(Sector)) %>% as.data.frame() Which gives me following output ClientID month test ASD Sep Auto,Auto,Finance DFG Oct Finance,Auto,Oil How I want is to count sectors as well ClientID month test ASD Sep Auto:2,Finance:1 DFG Oct Finance:1,Auto:1,Oil:1 How can I achieve it with dplyr? 回答1: We can try df %>% group_by(client_id, month, Sector) %>% tally() %>% group_by(client