Re: expanding a list
- To: mathgroup at smc.vnet.net
- Subject: [mg42636] Re: expanding a list
- From: "AngleWyrm" <no_spam_anglewyrm at hotmail.com>
- Date: Fri, 18 Jul 2003 05:25:40 -0400 (EDT)
- Organization: Comcast Online
- References: <bf5ksa$mj0$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"Alan Kelly" <Alan.Kelly at tcd.ie> wrote in message news:bf5ksa$mj0$1 at smc.vnet.net... > 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. Here's one approach: in[1]: plist = {0.252, 0.252, 0.257, 0.235}; flist = {7, 5, 6, 4}; newList = {}; Table[ PadRight[newList, flist[[i]], plist[[i]] ], {i, Length[flist]}] // Flatten out[1]: {0.252, 0.252, 0.252, 0.252, 0.252, 0.252, 0.252, 0.252, 0.252, 0.252, 0.252, 0.252, 0.257, 0.257, 0.257, 0.257, 0.257, 0.257, 0.235, 0.235, 0.235, 0.235} in[2]: Length[%] out[2]: 22 -Jonathan