r - Transforming a list into a dataframe -
i have following list (fyi, list part of bioconductor package "gagedata" , can installed follow):
source("http://bioconductor.org/bioclite.r") bioclite("gagedata")
and then
library(gagedata) data(kegg.sets.ko) kegg.sets.ko[1:2] $`ko00010 glycolysis / gluconeogenesis` [1] "k00001" "k00002" "k00016" "k00114" "k00121" "k00128" "k00129" "k00131" "k00134" "k00149" "k00150" "k00161" "k00162" "k00163" [15] "k00169" "k00170" "k00171" "k00172" "k00382" "k00627" "k00844" "k00845" "k00850" "k00873" "k00886" "k00918" "k00927" "k01084" [29] "k01085" "k01222" "k01223" "k01568" "k01596" "k01610" "k01622" "k01623" "k01624" "k01689" "k01785" "k01792" "k01803" "k01810" [43] "k01834" "k01835" "k01837" "k01895" "k01905" "k02446" "k02749" "k02750" "k02752" "k02753" "k02777" "k02778" "k02779" "k02790" [57] "k02791" "k03738" "k03841" "k04022" "k04041" "k04072" "k05344" "k06859" "k08074" "k10705" "k11389" "k11532" "k11645" "k12406" [71] "k12407" "k13810" "k13951" "k13952" "k13953" "k13954" "k13980" "k13997" "k14028" "k14029" "k14085" "k15633" "k15634" "k15635" [85] "k15778" "k15779" "k15916" "k15917" "k16305" "k16306" "k16370" $`ko00020 citrate cycle (tca cycle)` [1] "k00024" "k00025" "k00026" "k00030" "k00031" "k00161" "k00162" "k00163" "k00164" "k00169" "k00170" "k00171" "k00172" "k00174" [15] "k00175" "k00176" "k00177" "k00234" "k00235" "k00236" "k00237" "k00239" "k00240" "k00241" "k00242" "k00244" "k00245" "k00246" [29] "k00247" "k00382" "k00627" "k00658" "k01596" "k01610" "k01643" "k01644" "k01646" "k01647" "k01648" "k01676" "k01677" "k01678" [43] "k01679" "k01681" "k01682" "k01899" "k01900" "k01902" "k01903" "k01958" "k01959" "k01960" "k13997" "k15230" "k15231"
the list groups number of k-ids several classes. k-ids not unique, meaning can present in more 1 class. build dataframe list 2 columns, first unique k-ids , second classes present. example k-id k00170 present in both groups in subset above have following:
koid class k00170 ko00010 glycolysis / gluconeogenesis; ko00020 citrate cycle (tca cycle)
kegg.sets.ko <- list(class_one = 1:5, class_two = 3:10) # example data make copy-pasteable. df <- data.frame(koid = unique(c(kegg.sets.ko, recursive = true))) df$class <- vapply(df$koid, function(id) paste(names(kegg.sets.ko)[vapply(kegg.sets.ko, function(x) id %in% x, logical(1))] , collapse = '; ') , character(1))
Comments
Post a Comment