r - Revert split effect in a list -
i have list , convert data.frame 2 columns. problem length of list elements not equal, here example of how data looks:
my.list $a1cf [1] "a1cf" "apobec1" "cugbp2" "khsrp" "syncrip" "tnpo2" $a2ld1 [1] "a2ld1" "prpsap2" "rpl15" "tanc1" $a2m [1] "a2m" "adam19" "adamts1" "ambp" "anxa6" "apoe"
this list comes previous data.frame:
my.list <- split(df$v2, df$v1) df v1 v2 1 a1bg a1bg 2 a1bg crisp3 3 a1cf a1cf 4 a1cf apobec1 5 a1cf cugbp2 6 a1cf khsrp 7 a1cf syncrip 8 a1cf tnpo2 9 a2ld1 a2ld1 10 a2ld1 prpsap2 11 a2ld1 rpl15 12 a2ld1 tanc1 13 a2m a2m 14 a2m adam19 15 a2m adamts1 16 a2m ambp 17 a2m anxa6 18 a2m apoe
where elements corresponding ab1g removed. revert split effect obtain same structure:
new.df a1cf a1cf a1cf apobec1 a1cf cugbp2 a1cf khsrp a1cf syncrip a1cf tnpo2 a2ld1 a2ld1 a2ld1 prpsap2 a2ld1 rpl15 a2ld1 tanc1 a2m a2m a2m adam19 a2m adamts1 a2m ambp a2m anxa6 a2m apoe
i have tried with: df.new <- do.call(rbind, my.list)
, didn't work.
many thanks
using these dummy data,
ll <- list(a = letters[3:6], b = letters[1:10], c = letters[1:2]) stack(ll)
or
reshape2::melt(ll, id=1)
or
plyr::ldply(ll, cbind)
should give right format
Comments
Post a Comment