MathGroup Archive 2006

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

Search the Archive

Re: List Question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67918] Re: List Question
  • From: albert <awnl at arcor.de>
  • Date: Thu, 13 Jul 2006 06:53:04 -0400 (EDT)
  • References: <e92e03$ljm$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Simon Bale wrote:

> Hi,
> 
> I have a list with the following structure:
> 
> {{x1,y1},{x2,y2},{x3,y3,z3},{x4,y4}...}
> 
> As you can see some of the data points have three elements. I would
> like to remove these z elements so that the list has a structure
> {{x1,y1},{x2,y2},{x3,y3},{x4,y4}...}. I'm not sure how to achieve this
> so any
> help is greatly appreciated.

lst = {{x1, y1}, {x2, y2}, {x3, y3, z3}, {x4, y4}}; 
Replace[lst, {a_, b_, c__} -> {a, b}, {1}]

Using Replace with a third argument gives you good control of where the
replacement is tried. Using c__ instead just c__ will make the Replace work
even if there are data points with more than three elements...

hth,

albert


  • Prev by Date: Re: Question on using Table in module
  • Next by Date: Re: List Question
  • Previous by thread: RE: List Question
  • Next by thread: Re: List Question