melt + strsplit, or opposite to aggregate

前端 未结 4 1816
忘了有多久
忘了有多久 2021-01-22 07:32

I have a little question that seems to be so easy in concept, but I cannot find the way to do it...

Say I have a data.frame df2 with a column listing car brands and anot

4条回答
  •  一向
    一向 (楼主)
    2021-01-22 08:09

    These days I would use tidytext::unnest_tokens for this task:

    library(tidytext)
    df2 %>% 
      unnest_tokens(model, models, token = "regex", pattern = ",")
    
    # A tibble: 10 x 2
        brand model
        
     1      a    a1
     2      a    a2
     3      a    a3
     4      b    b1
     5      b    b2
     6      c    c1
     7      d    d1
     8      d    d2
     9      d    d3
    10      d    d4
    

提交回复
热议问题