Re:expanding a list - Thanks!
- To: mathgroup at smc.vnet.net
- Subject: [mg42696] Re:[mg42593] expanding a list - Thanks!
- From: Alan Kelly <Alan.Kelly at tcd.ie>
- Date: Mon, 21 Jul 2003 05:15:23 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Deal All - I posted my thanks to two respondents (see below) on Thursday last - but by Friday afternoon I had had close to thirty replies along the same lines as given below - too many to reply to individually, so many thanks to all of you for taking the trouble to answer my question. best wishes, Alan Kelly >My thanks to Mihajlo Vanevic and Bob Hanlon for answering my question >(see below). I asked for an elegant and efficient solution and >that's what I got! > >Mihajlo suggested: > >MapThread[Table[#1, {#2}] &, {plist, flist}] >or >Flatten@MapThread[Table[#1, {#2}] &, {plist, flist}] > >and Bog suggested: >Flatten[Table[#[[1]], {#[[2]]}] & /@ Transpose[{plist, flist}]] > >Again, many thanks to both. Now all I have to do is understand how >these actually work!! >Alan Kelly > > >My original question >_______________________________________________________________ >Hi all, >I believe that this is a rather elementary question, but I am not >aware of a simple, elegant and efficient solution. I have searched >the MathGroup archive, but with no success. > >I have two lists - both of the same length. The first contains a >list of probabilities. For example, suppose the list length is 4 >(although in practice it would be much longer) and is of the >following form: >plist = {0.252, 0.252, 0.257, 0.235}. >The second contains a list of integers: >flist = {7,5,6,4}. >I wish to take the first element of plist and replicate that value >using the first element of flist. Similarly for the remaining >elements. >I should finish with a list of length 7+5+6+4 or 22. >Any suggestion please. >Many thanks, >Alan Kelly >Trinity College Dublin > >+-------------------------------------------------------+ > Dr. Alan Kelly E-mail akelly at mail.tcd.ie > Biostatistician Phone: +353-1-608 1385 or 608 1087 > Fax: +353-1-403 1211 or 403 1212 > > > >Director of the Small Area Health Research Unit > >Department of Community Health & General Practice > >Trinity Center for Health Sciences >AMNCH >Tallaght Hospital >Dublin 24 >Ireland > > > http://www.tcd.ie/Community_Health/SAHRU/index.html > >Please note that electronic mail to, from or within the College, may be the >subject of a request under the Freedom of Information Act.