MathGroup Archive 2009

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

Search the Archive

Re: simple question

  • To: mathgroup at
  • Subject: [mg105239] Re: [mg105202] simple question
  • From: Bob Hanlon <hanlonr at>
  • Date: Wed, 25 Nov 2009 02:33:22 -0500 (EST)
  • Reply-to: hanlonr at

groupBy[mat_, positions_] :=
 GatherBy[mat, Part[#, positions] &]

Bob Hanlon

---- Francisco Gutierrez <fgutiers2002 at> wrote: 

Dear List:
I have the following list:
I want to group it, so that the sublists of ejemplo1 that have identical values at positions 4 and 5 are gathered together. So I did the following code:
Split[ Sort[ejemplo1,#1[[4]]>=#2[[4]] && #1[[5]]>=#2[[5]] &],Take[#1,{4,5}]==Take[#2,{4,5}]&]
Works! The output in effect is:
precisely what I wanted.
Now, how can I create a function for the general case (instead of fixed positions 4 and 5, an arbitrary number of positions that act as "gathering parameter")?

  • Prev by Date: Re: Re: Undo in Mathematica
  • Next by Date: Re: simple question
  • Previous by thread: Re: Re: part assigned sequence behavior puzzling
  • Next by thread: Re: simple question