Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Using Select with arrays? (Relative newbie)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg54249] Re: Using Select with arrays? (Relative newbie)
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Mon, 14 Feb 2005 21:50:43 -0500 (EST)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

data={
      {1,1,string1,c,d} ,
      {1,2,string2,c,d} ,
      {1,3,string3,c,d} ,
      {1,4,string4,c,d},
       {2,1,string1,c,d},
       {2,2,string2,c,d} ,
      {3,1,string3,c,d} ,
      {4,1,string2,c,d},
       {4,2,string4,c,d}};

To select by value of first position

Select[data,First[#]==1&]

{{1, 1, string1, c, d}, {1, 2, string2, c, d}, 
  {1, 3, string3, c, d}, {1, 4, string4, c, d}}

To select ALL members of subset with with specified value in first position 
and maximum value in second position

pickMax2[data_, firstVal_] := Module[{t},
      Select[
        t=Select[data,First[#]==firstVal&],
        #[[2]]==Max[t[[All,2]]]&]];

The result is a list of lists since there presumably could be more than one

pickMax2[data,1]

{{1, 4, string4, c, d}}

pickMax2[data,#]& /@ Range[Max[data[[All,1]]]]

{{{1, 4, string4, c, d}}, {{2, 2, string2, c, d}}, 
  {{3, 1, string3, c, d}}, {{4, 2, string4, c, d}}}


Bob Hanlon

> 
> From: Hugo Mallinson <hfm21 at cam.ac.uk>
To: mathgroup at smc.vnet.net
> Date: 2005/02/13 Sun PM 10:17:04 EST
> To: mathgroup at smc.vnet.net
> Subject: [mg54249]  Using Select with arrays? (Relative newbie)
> 
> The subject might not be entirely correct, but here is my problem:
> 
> I have a list of 5-variable data points like
> 
> data = {
> {1, 1, string1, c, d}
> {1, 2, string2, c, d}
> {1, 3, string3, c, d}
> {1, 4, string4, c, d}
> {2, 1, string1, c, d}
> {2, 2, string2, c, d}
> {3, 1, string3, c, d}
> {4, 1, string2, c, d}
> {4, 2, string4, c, d}
> }
> 
> 
> and I want to extract just the points that have 1 (or 2, etc) as their 
> first value. I think I should do something like
> 
> Select[data, {1, _Integer, _String, _Integer, _Integer}]
> 
> but that doesn't work.
> 
> Having done that I need to find the maximum value of #2 for each 
> string, which I presumably do by the same method as above to extract 
> all string1 (or ...2) and then use Map[] and Max[]. I would do this all 
> with For loops (revealing my lack of Mathematica chops :-) ) but I'd 
> really like to learn how to do this sort of extraction in a 
> Mathematica-y way. Any help would be greatly appreciated!
> 
> Hugo
> 
> 


  • Prev by Date: Re: Fourier Transfer and a game?!?!
  • Next by Date: Re: Problem using Evaluate[] inside a Plot command. 5.1
  • Previous by thread: Re: Using Select with arrays? (Relative newbie)
  • Next by thread: Re: Using Select with arrays? (Relative newbie)