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

前端 未结 6 918
礼貌的吻别
礼貌的吻别 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条回答
  •  一整个雨季
    2020-12-30 13:29

    Since you asked for a plyr solution, here you go:

    ddply(df, .(Type), function(foo) {
        values <- unlist(strsplit(c(foo$Values), ";"))
        data.frame(Type = rep(unique(foo$Type), length(values)), Values = values)
        })
    

提交回复
热议问题