Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: "expanding a list"

  • To: mathgroup at
  • Subject: [mg57897] Re: "expanding a list"
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at>
  • Date: Sun, 12 Jun 2005 04:34:18 -0400 (EDT)
  • Organization: New York University
  • References: <d8bd00$fj0$>
  • Reply-to: jmg336 at
  • Sender: owner-wri-mathgroup at

Mark Coleman wrote:
> Greetings,
> I'd like to construct a list as follows. Say I have a list of reals  
> {x1,x2,x3,...xn}, and another list of integers {r,s}. I'd like to  
> make a new list
> {{x1,x1,x1,...},{x2,x2,x2....},{x3,x3,x3,...},....,{xn,xn,xn,...}},  
> where the first sublist is of length r, and the remaining sublists  
> are of length s.

Hi Mark,

I think the following lines do the trick (first we create some data, 
then we define a function called "listExpand"):

data = {1.02, 5.7, 3.987, 4.212, 9.11}


listExpand[L_, r_, s_] := FlattenAt[{Table[L[[1]], {r}],
      (Table[#1, {s}] & ) /@ Rest[L]}, 2];

listExpand[data, 3, 5]


Best regards,

  • Prev by Date: Re: Applying function to nested lists
  • Next by Date: Re: Applying function to nested lists
  • Previous by thread: Re: "expanding a list"
  • Next by thread: NMaximise Problem