I have a list {a,b,c,d} and a second list where is how many times the elements of the first list repeat {1,4,2,6} (the order is according with the first list). Then I need to create a third list with this information: {a,b,b,b,b,c,c,d,d,d,d,d,d}. What can I do?
Asked
Active
Viewed 217 times
2
J. M.'s missing motivation
- 124,525
- 11
- 401
- 574
Ask8
- 637
- 3
- 6
1 Answers
1
Catenate @ MapThread[ConstantArray, {{a, b, c, d}, {1, 4, 2, 6}}]
{a, b, b, b, b, c, c, d, d, d, d, d, d}
m_goldberg
- 107,779
- 16
- 103
- 257
Alan
- 13,686
- 19
- 38
-
-
1
Catenatenot needed.Flatten@MapThread[ConstantArray, {{a, b, c, d}, {1, 4, 2, 6}}]works. Has advantage of working in older versions withoutCatenate. – m_goldberg Mar 22 '18 at 03:06
Flatten[MapThread[Table, {{a, b, c, d}, {1, 4, 2, 6}}]]– J. M.'s missing motivation Mar 22 '18 at 00:53