0

I am trying to create a social graph that tags a product to the issues. I have tibble dataframe with character vectors that consist of a column with multiple product and a column with multiple issues. I would need to split the column to ensure one product is map to one issue. I am not too sure how can I do it.

Product Issues
c("iphone", "screen") spoil
tablet c("proof", "fail")

The outcome of the table should be the table below:

Product Issues
iphone spoil
screen spoil
tablet proof
tablet fail

example data dput:

structure(list(product_tags = list(c("jim", "choice"), c("misinformed", 
"update", "iphone 13 show", "update one"), c("wallpaper", "ios15"
), c("hello", "io 16", "apple music"), c("default", "wallpaper"
), "issue", "machine", "escalate", "copy", c("update 16", "tomorow"
), "cloud", "macbook", c("notification", "lock screen"), c("unlock 8", 
"ipad", "support", "ipad"), c("notification", "lock screen")), 
    issue_tags = list("third", "learn", "get back", c("stop playing", 
    "ios16", "help"), "bring", "category", "minor", "iphone macbook", 
        c("work", "detail"), "iphne", c("agree back", "google"
        ), c("laptop", "business", "fine"), "change", c("proof", 
        "fail"), "go back")), row.names = c(NA, -15L), class = c("tbl_df", 
"tbl", "data.frame"))


  • `library(tidyr)` then `unnest(dat, cols=everything())` – thelatemail Oct 31 '22 at 03:00
  • @thelatemail I tried using it but I received an error if both my product and issues consist of a character vector – Rshiny Learner Oct 31 '22 at 03:06
  • Works for me after recreating your data as shown - `dat <- data.frame( Product = I(list(c("iphone", "screen"), "tablet")), Issues = I(list("spoil", c("proof", "fail"))) )` – thelatemail Oct 31 '22 at 03:07
  • @thelatemail i uploaded an example of the data. at line 14 both the product and issues are list. and by using unnest it seems to be an error – Rshiny Learner Oct 31 '22 at 03:15
  • Yep, you can't do that. From `?unnest` - "*If you 'unnest()' multiple columns, parallel entries must be of compatible sizes, i.e. they're either equal or length 1 (following the standard tidyverse recycling rules).*" – thelatemail Oct 31 '22 at 03:17
  • You could do it via a base R method - `data.frame(do.call(rbind, do.call(Map, c(cbind, dat))))` or similar, but it might not make sense what rows correspond to what values. – thelatemail Oct 31 '22 at 03:19

0 Answers0