Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: Grouping {x,y z} data set

  • To: mathgroup at smc.vnet.net
  • Subject: [mg99623] Re: [mg99583] Grouping {x,y z} data set
  • From: Fred Simons <f.h.simons at tue.nl>
  • Date: Sat, 9 May 2009 03:23:20 -0400 (EDT)
  • References: <200905080418.AAA16631@smc.vnet.net>

graser wrote:
> Hi!
>
> I have a question for you.
>
> I have arbitrary data set.
>
> For example,
>
> Data={{x_1,y_1,z_1},{x_2,y_2,z_1},{x_1, y_2, z_3},........{x_n, y_m,
> z_L}}
>
> I tried to group this data set depending on z value.
>
> I mean I try to select all x, y values with same z value.
>
> But they are not evenly distributed and they are not integer either.
>
> please help me!
>
> Thanks!
>
>
>
>   
In Mathematica 7 you can use GatherBy. Here is an example that will work 
not only for integers:

IIn[1]:= data=RandomInteger[{1,5}, {20,3}]

Out[1]= 
{{2,5,4},{3,4,4},{1,1,5},{2,3,2},{4,4,4},{1,5,2},{5,3,4},{1,2,5},{3,3,4},{5,5,5},{2,5,3},{2,2,2},{3,2,1},{5,3,2},{1,1,5},{5,3,2},{5,5,4},{5,4,3},{3,4,4},{4,3,1}}

In[2]:= Map[Most, GatherBy[data, #[[3]]&], {2}]

Out[2]= 
{{{2,5},{3,4},{4,4},{5,3},{3,3},{5,5},{3,4}},{{1,1},{1,2},{5,5},{1,1}},{{2,3},{1,5},{2,2},{5,3},{5,3}},{{2,5},{5,4}},{{3,2},{4,3}}}

Fred Simons
Eindhoven University of Technology


  • Prev by Date: Re: TraditionForm Appears to be Inconsistent
  • Next by Date: Re: TraditionForm Appears to be Inconsistent
  • Previous by thread: Grouping {x,y z} data set
  • Next by thread: Re: Grouping {x,y z} data set