[英]How to change the format of a list in R?
I would like to convert the format of my list2 to be like list1, where those letters in "from" go to Names column and whatever that is in "to" go to Value column like in list1.我想将我的list2的格式转换为list1,其中“from”中的那些字母转到名称列,而“to”中的任何内容都转到list1中的值列。 In list1, from and to values are associated.
在 list1 中,from 和 to 值是关联的。 For example, "sce00010" goes with "Glycolysis/Glucogneogeneis".
例如,“sce00010”与“糖酵解/Glucogneogeneis”一起使用。
Is there any way to do so?有什么办法吗? Tnx!
天呐!
Structure of list2: 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
structure of list1: 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"
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"
Created on 2022-06-19 by the reprex package (v2.0.1)由reprex 包于 2022-06-19 创建 (v2.0.1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.