我有一个包含3个级别的嵌套列表:
字符串的长度(我不关心完成所有操作,它仅用于列表的排序)
类别(我想保留在输出中)
元素(我也想保留的字符串)
我想取消此列表的结构/使其变平,以获得具有列表中顺序的字符向量,并且所有元素都应命名为:
“类别”“ __”“元素”
我无法完成此任务。我的问题是,要么2级都没有保留名称,要么也保留了索引,因此我得到了错误的名称(例如Dog,Dog1,Dog2,Dog3而不是Dog)。
我已经尝试过第一个purrr :: flatten->结果列表看起来不错(我认为)。
然后,我尝试取消平展输出的列表,以将所有这些项转换为字符向量,这就是我得到的位置。
我收到的元素名称如下:
TCRBV11-031 TCRBV11-032 TCRBV11-033
但它们都应该是TCRBV11-03
如何保留子列表的名称并将其与元素组合。最好在中间加上“ _”?
编辑:示例列表的输出:
list(`11` = list(`TCRBV06-01` = "CAIDRSYEQYF", `TCRBV29-01` = "CSADRKETQYF"),
`12` = list(`TCRBV05-06` = "CASSRPNTEAFF", `TCRBV06-01` = "CASGHKNTEAFF",
`TCRBV07-03` = "CASSLRLHEQYF"), `13` = list(`TCRBV02-01` = "CASQGIVGYEQYF",
`TCRBV05-01` = "CASTGSLNTEAFF", `TCRBV06-04` = "CASSLGKNTEAFF",
`TCRBV07-03` = "CASSLTEGGGYTF", `TCRBV07-08` = "CASSPDTNTEAFF",
`TCRBV07-09` = "CASSPDRDTEAFF", `TCRBV10-03` = "CAISMISNQPQHF",
`TCRBV18-01` = "CASSPPETYEQYF", `TCRBV19-01` = "CASSIGGSTEAFF",
`TCRBV20-01` = c("CSAMAYRADGYTF", "CSAREAQAETQYF", "CSAITSRVDGYTF"
), `TCRBV27-01` = "CASSFPGGYGYTF"), `14` = list(`TCRBV05-06` = "CASSLVGASYEQYF",
`TCRBV06-01` = c("CASRQGQENQPQHF", "CASRRQGEGTEAFF"),
`TCRBV07-09` = "CASSPGVSGNTIYF", `TCRBV10-02` = "CASSPAEGGYEQYF",
`TCRBV13-01` = "CASSLGQGVYEQYF", `TCRBV24-01` = "CATRSTGANTEAFF"),
`15` = list(`TCRBV02-01` = "CASSDVLAGGPEQYF", `TCRBV04-01` = "CASSQDPAGGRKLFF",
`TCRBV04-03` = "CASSQDSTALYGYTF", `TCRBV05-01` = "CASSFEDRGAGGYTF",
`TCRBV05-04` = c("CASGLTGEGNTEAFF", "CASSPVSSRTDTQYF"
), `TCRBV06-04` = "CASSDSSSGYNEQFF", `TCRBV07-09` = "CASSPTSGVGSEQFF",
`TCRBV10-03` = "CAISGGGGSTNIQYF", `TCRBV11-03` = "CASSDETGAGYEQFF",
`TCRBV13-01` = "CASSSSTALYNEQFF", `TCRBV18-01` = "CASSPLAGGSNEQYF",
`TCRBV25-01` = "CASSEDRGLDQPQHF", `TCRBV28-01` = "CASSPVAGGHYEQYF",
`TCRBV30-01` = "CAWSWGGGLGEKLFF"), `16` = list(`TCRBV04-01` = "CASSQVVIPPGEKLFF",
`TCRBV14-01` = "CASSQPGLLGTDTQYF", `TCRBV15-01` = "CATSRWGTGELTEAFF",
`TCRBV19-01` = "CASSIGTADIYNEQFF", `TCRBV20-01` = "CSARGQTSGFTYEQYF"),
`17` = list(`TCRBV04-01` = "CASSQDPRTASYNEQFF", `TCRBV04-02` = "CASSQDLETSGDDIQYF",
`TCRBV25-01` = "CASSEYTTGEVTDTQYF"), `18` = list(`TCRBV12-05` = "CASGLVGGVLSGANVLTF"),
`19` = list(`TCRBV04-03` = "CASSQDPKGGLLNTGELFF"))