MathGroup Archive 2002

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

Search the Archive

Re: help with simple data transform

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37741] Re: help with simple data transform
  • From: Tom Burton <tburton at brahea.com>
  • Date: Mon, 11 Nov 2002 05:09:54 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On 11/10/02 2:43 AM, in article aqld8o$bie$1 at smc.vnet.net, "Terrell
Mitchell" <usenet at twocedars.mailshell.com> wrote:

> I will have data of the form
> n n n n 
> n n n n n n
> n n n n n
> n n
> I can read this into lists and end up with
> {n,n,n,n},{n,n,n,n,n,n},{n,n,n,n,n},{n,n}
> I need to turn this into
> {n,{n,n,n}},{n,{n,n,n,n,n}},{n,{n,n,n,n}},{n,{n}}

Let

t = {{a, b, c, d, e}, {f, g, h}, {i, j}, {k}};

Then a suitable transformation is

r = {(a_)?AtomQ, b__} :> {a, {b}}

so that

t /. r

gives you what you want. If you choose to process the members of list t one
at a time (or if you give t some Head other than List), then the simpler
pattern {a_, b__} will do. The more complicated pattern avoids a match with
the entire list as a unit (i.e., at "level 0").

Tom Burton




  • Prev by Date: Outlines? (Or, opening and closing cells level by level?)
  • Next by Date: Re: How to use error message return values
  • Previous by thread: Re: help with simple data transform
  • Next by thread: Re: help with simple data transform