-1

I have a data frame as shown below, i need to concatenate the strings in issue column by grouping ID,Location and Customer. enter image description here ID Location Customer Issue 1 x a Issue1 2 y b Issue2 3 z c Issue3 1 x a Issue4 2 y b Issue5 2 y b Issue6

my result should look like

enter image description here

ID Location Customer Issues 1 x a Issue1, Issue4 2 y b Issue2, Issue5, Issue6 3 z c Issue3

Can anyone help with the r code for this?

Also i need to list the unique issues if issues are repeating the grouping

1 Answers1

0
library(dplyr)
df %>%
  group_by(Id, Location, Customer) %>%
  mutate(Issue = paste0(Issue, collapse = ",")) %>%
  distinct()
# A tibble: 3 x 4
# Groups:   ID, Location, Customer [3]
#      ID Location Customer Issue           
#      <dbl> <fct>    <fct>   <chr>               
#1     1 x        a       Issue1,Issue4       
#2     2 y        b       Issue2,Issue5,Issue6
#3     3 z        c       Issue3 
deepseefan
  • 3,701
  • 3
  • 18
  • 31