0

Hi I used the Apriori model in R to find a association rules. The model output look as following:

  id                                 lhs      rhr      support confidence     lift
    1         {BENEFIT SERVICE,ERBORIAN} {BENEFIT} 0.001362644  0.6163793 2.557921
    2 {BENEFIT SERVICE,MAKE UP FOR EVER} {BENEFIT} 0.002982571  0.6113281 2.536959
    3          {BENEFIT SERVICE,CLARINS} {BENEFIT} 0.002649057  0.5914894 2.454629

my goal is to split the lhs column and actual duplicate the other column consistently.

as follow:

   id                     lhs                rhr      support confidence     lift
    1         BENEFIT SERVICE            BENEFIT  0.001362644  0.6163793 2.557921
    1         ERBORIAN                   BENEFIT  0.001362644  0.6163793 2.557921
    2         BENEFIT SERVICE            BENEFIT  0.002982571  0.6113281 2.536959
    2         MAKE UP FOR EVER           BENEFIT  0.002982571  0.6113281 2.536959
    3         BENEFIT SERVICE            BENEFIT  0.002649057  0.5914894 2.454629
    3         CLARINS                    BENEFIT  0.002649057  0.5914894 2.454629

any idea how to do this kind of data manipulation? Thanks in advance

Andre Elrico
  • 10,956
  • 6
  • 50
  • 69
David_12
  • 17
  • 1
  • 4
  • 1
    You can use function `separate_rows` from `tidyr` package. You might need to remove the brackets `{}` first. – AntoniosK Aug 30 '18 at 11:50
  • Thanks @AntoniosK it's work perfect. Any idea how I can use to remove the brackets? when I try to use the lapply(df1, gsub, pattern='{', replacement='') I'm getting error invalid regular expression '{', reason 'Missing '}' how I can use the '{' that R will not think it's part of code – David_12 Aug 30 '18 at 12:16
  • try `\\{` instead of `{` (and `\\{|}` is even better) – Vincent Bonhomme Aug 30 '18 at 12:31
  • @VincentBonhomme df2 <- lapply(df1, gsub, pattern='\\{', replacement='') what I missing here? still not work Thanks – David_12 Aug 30 '18 at 13:06
  • try `gsub("\\{|}", "", df$ldhs)`. not sure how your data is formatted. – Vincent Bonhomme Aug 30 '18 at 13:10

0 Answers0