英文:
How to repeat a list of items in a range based on a specified value for each item in the range ing google sheets?
问题
=ARRAYFORMULA(FLATTEN(SPLIT(JOIN(",", REPT(A2:A4&",", B2:B4)), ",")))
英文:
I would like to repeat a list in google sheets where each item is repeated a different number of times based on a value in a different cell.
What formula can I use to achieve this?
List:
Apple
Banana
Orange
Desired Output:
Apple
Apple
Banana
Banana
Banana
Banana
Orange
Orange
Orange
Items | # of rept |
---|---|
Apple | 2 |
Banana | 4 |
Orange | 3 |
=ARRAYFORMULA(FLATTEN(IF(SEQUENCE(ROWS(D2:D42),10),D2:D42)))
This is all I can think of but the 10 needs to be a custom value depending on the value associated with the unique cell in D2:D42.
答案1
得分: 1
=ARRAYFORMULA(TOCOL(SPLIT(JOIN(,REPT(A2:A&"ζ",B2:B)),"ζ")))
=ARRAYFORMULA(TOCOL(MAP(A2:A,B2:B,LAMBDA(a,b,IF(SEQUENCE(1,b),a))),3))
=TOCOL(MAP(A2:A,B2:B,LAMBDA(a,b,CHOOSECOLS(a,SEQUENCE(1,b,1,0)))),3)
英文:
Here are some options:
=ARRAYFORMULA(TOCOL(SPLIT(JOIN(,REPT(A2:A&"ζ",B2:B)),"ζ")))
=ARRAYFORMULA(TOCOL(MAP(A2:A,B2:B,LAMBDA(a,b,IF(SEQUENCE(1,b),a))),3))
=TOCOL(MAP(A2:A,B2:B,LAMBDA(a,b,CHOOSECOLS(a,SEQUENCE(1,b,1,0)))),3)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论