reshape dataframe based on a string split in one column in R

前端 未结 6 1018
礼貌的吻别
礼貌的吻别 2020-12-30 12:58

I have the following data structure

ID  Type  Values
1   A     5; 7; 8
2   A     6
3   B     2; 3

and I would like to reshape it to the fol

6条回答
  •  -上瘾入骨i
    2020-12-30 13:13

    A data.table approach for coding elegance

    library(data.table)
    DT <- data.table(dat)
    DT[, list(Value = unlist(strsplit(as.character(Values), '; '))), by = list(ID, Type)]
    

提交回复
热议问题