简体   繁体   English

通过从 R 中的另一个重复模式创建新列表

[英]Create new list by repeating pattern from another one in R

I have a list of color such as;我有一个颜色列表,例如;

list_color<-c("#8bf6f8","#ac807d") ( list_color[1] correspond to the color of the fist list of list (here Homo_sapiens)) list_color<-c("#8bf6f8","#ac807d") ( list_color[1]对应list的第一个list的颜色(这里是Homo_sapiens))

and a list of list such as:和一个列表,例如:

list(Homo_sapiens = "Group1", Mus_musclus = c("Group2", 
"Group3", "Group4", "Group5"))

$Homo_sapiens
[1] "G1"

$Mus_musclus
[1] "G2" "G3" "G4" "G5"

and I would like to create a new_list_color where for each list I rep the color in list_color (the rep is the number of Groups within list)我想创建一个new_list_color ,对于每个列表,我在list_color中表示颜色(rep 是列表中的组数)

Then this list should look like:那么这个列表应该如下所示:

new_list_color<-c("#8bf6f8","#ac807d","#ac807d","#ac807d","#ac807d")

If the second list is called data you can do -如果第二个列表被称为data你可以做 -

new_list_color <- rep(list_color, lengths(data))
new_list_color

#[1] "#8bf6f8" "#ac807d" "#ac807d" "#ac807d" "#ac807d"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM