MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

expanding a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42622] expanding a list
  • From: google at scholar.freesurf.fr (Irasban)
  • Date: Fri, 18 Jul 2003 05:25:18 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Boostrapping a dataset ?

What you want to do can be programmed in several ways.

This version should be easy to use and understand:

Flatten[MapThread[Table[#1, {#2}] &, {
           {a, b, c, d, e},
           {1, 5, 0, 4, 3}
}], 1]

{a, b, b, b, b, b, d, d, d, d, e, e, e}

The first sub list are the original figures (can be a list of almost any
Mathematica expression in fact), the second list
the repetition counts.  The final Flatten is needed to collapse the
resulting list of lists.

As illustrated in the example, you can use 0 to drop an element from
the list. Only integers are allowed in the second sublist.

I leave to you the task of writing this solution in the form
of a proper function with arguments.

Irasban

>> ====
Alan Kelly, told his fellow human beings:

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.

>> ====


  • Prev by Date: Re: expanding a list
  • Next by Date: RE: displaying a graphic without input
  • Previous by thread: Re: expanding a list
  • Next by thread: RE: expanding a list