I have a dataframe below and I am summarizing it based on 2 columns
samdt <- structure(list(Domain = c("a", "a", "b", "b", "b"),
sub_domain = c("a1", "a1", "b1", "a1", "b1"),
Reviews = c(1234, 2311, 3123, 4311, 5211),
Ratings = c(1,2,1,2,1)), row.names = c(NA,-5L), class = c("tbl_df", "tbl", "data.frame"))
Summary
samdt %>% group_by(Domain, sub_domain) %>% summarise(nReviews = n())
# A tibble: 3 x 3
# Groups: Domain [2]
Domain sub_domain nReviews
<chr> <chr> <int>
1 a a1 2
2 b a1 1
3 b b1 2
This is all. But can we add another column to above dataframe so that the "Ratings" value are concatenated
Expected output
Domain sub_domain nReviews Ratings
<chr> <chr> <int> <chr>
1 a a1 2 1,2
2 b a1 1 2
3 b b1 2 1,1