Repeat objects in list in R
<p>I have two list files a and b:</p>

<pre><code>a&lt;-list(1,5,8,2,6,4,9,5)
b&lt;-list(2,2,3,2,4,1,3,1)
</code></pre>

<p>I want every object in list a to repeat "matched objects of b" times, respectively.
The expected result is as follows:</p>

<pre><code>[[1]]
[1] 1 1

[[2]]
[1] 5 5

[[3]]
[1] 8 8 8

[[4]]
[1] 2 2

[[5]]
[1] 6 6 6 6

[[6]]
[1] 4

[[7]]
[1] 9 9 9

[[8]]
[1] 5
</code></pre>

<p>I use the code: <code>lapply(1:length(a), function(x) {rep(a[[x]],b[[x]])})</code>But I want to explore other ways. Thank you for help!</p>