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: [mg99604] Re: [mg99583] Grouping {x,y z} data set
  • From: Adriano Pascoletti <adriano.pascoletti at dimi.uniud.it>
  • Date: Sat, 9 May 2009 03:19:53 -0400 (EDT)
  • References: <200905080418.AAA16631@smc.vnet.net>

Consider this list of triples:

t = {{68, 53, 2}, {57, 48, 5}, {3, 40, 4}, {56, 27, 3}, {2, 23, 3},
 {2, 24, 1}, {34, 91, 2}, {14, 69, 5}, {25, 67, 0}, {43, 72, 2}};

1. Solution using SortBy and SplitBy

SplitBy[SortBy[t, Last], Last] gives

{{{25, 67, 0}}, {{2, 24, 1}}, {{34, 91, 2}, {43, 72, 2}, {68, 53, 2}}, {{2,
   23, 3}, {56, 27, 3}}, {{3, 40, 4}}, {{14, 69, 5}, {57, 48, 5}}}


2. Solution using Sow and Reap


Reap[(Sow[Most[#1], Last[#1]] & ) /@ t, _, #1 -> #2 & ][[2]] gives


 {2 -> {{68, 53}, {34, 91}, {43, 72}}, 5 -> {{57, 48}, {14, 69}},
   4 -> {{3, 40}}, 3 -> {{56, 27}, {2, 23}}, 1 -> {{2, 24}},
   0 -> {{25, 67}}}


Adriano Pascoletti


2009/5/8 graser <graser at gmail.com>

> 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!
>


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