Repeat objects in list in R -


i have 2 list files , b:

a<-list(1,5,8,2,6,4,9,5) b<-list(2,2,3,2,4,1,3,1) 

i want every object in list repeat "matched objects of b" times, respectively. expected result follows:

[[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 

i use code: lapply(1:length(a), function(x) {rep(a[[x]],b[[x]])})but want explore other ways. thank help!

you can use map!

map(rep, a, b) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -