【发布时间】:2021-04-08 08:40:38
【问题描述】:
我有一个包含 x.height, x.weight, y.height, y.length, z.weight, z.price 之类的元素名称的列表我想提取名称以 "x." 开头的元素,并通过删除它们的前缀 "x." 来重命名这些元素。这可以分两步完成:
list.new <- list.old %>% keep(str_detect(names(.), "^x."))
names(list.new) <- str_replace(names(list.new), "x", "")
我的第一个问题:如何在管道中结合这两个步骤?
最后,我想处理所有不同前缀 "y.", "z." 的列表,以获得一个新列表,其中包含重命名的子列表,例如:
List of 3
$ x:List of 2
..$ height: num 100
..$ weight: num 200
$ y:List of 2
..$ height: num 300
..$ length: num 400
$ z:List of 2
..$ weight: num 500
..$ price: num 600
是否可以使用单个管道来执行此操作?
【问题讨论】: