我想將我的list2的格式轉換為list1,其中“from”中的那些字母轉到名稱列,而“to”中的任何內容都轉到list1中的值列。在 list1 中,from 和 to 值是關聯的。例如,“sce00010”與“糖酵解/Glucogneogeneis”一起使用。
有什么辦法嗎?天吶!


list2的結構:
structure(list(from = c("sce00010", "sce00020", "sce00030", "sce00040",
"sce00051", "sce00052"), to = c("Glycolysis / Gluconeogenesis",
"Citrate cycle (TCA cycle)", "Pentose phosphate pathway", "Pentose and glucuronate interconversions",
"Fructose and mannose metabolism", "Galactose metabolism")), row.names = c(NA,
6L), class = "data.frame")
from to
1 sce00010 Glycolysis / Gluconeogenesis
2 sce00020 Citrate cycle (TCA cycle)
3 sce00030 Pentose phosphate pathway
4 sce00040 Pentose and glucuronate interconversions
5 sce00051 Fructose and mannose metabolism
6 sce00052 Galactose metabolism
list1的結構:
c(sce00010= "Glycolysis / Gluconeogenesis",
sce00020 = "Citrate cycle (TCA cycle)", sce00030= "Pentose phosphate pathway",
sce00040 = "Pentose and glucuronate interconversions",
sce00051= "Fructose and mannose metabolism",
sce00052= "Galactose metabolism")
sce00010
"Glycolysis / Gluconeogenesis"
sce00020
"Citrate cycle (TCA cycle)"
sce00030
"Pentose phosphate pathway"
sce00040
"Pentose and glucuronate interconversions"
sce00051
"Fructose and mannose metabolism"
sce00052
"Galactose metabolism"
uj5u.com熱心網友回復:
list1 <- list2$to
names(list1) <- list2$from
list1
#> sce00010
#> "Glycolysis / Gluconeogenesis"
#> sce00020
#> "Citrate cycle (TCA cycle)"
#> sce00030
#> "Pentose phosphate pathway"
#> sce00040
#> "Pentose and glucuronate interconversions"
#> sce00051
#> "Fructose and mannose metabolism"
#> sce00052
#> "Galactose metabolism"
由reprex 包于 2022-06-19 創建(v2.0.1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/493749.html
