Re: Using Select with arrays? (Relative newbie)

• To: mathgroup at smc.vnet.net
• Subject: [mg54241] Re: Using Select with arrays? (Relative newbie)
• From: DrBob <drbob at bigfoot.com>
• Date: Mon, 14 Feb 2005 21:50:34 -0500 (EST)
• References: <200502140317.WAA14058@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```First, I doubt you gave us the right value for data, since this would be the result:

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}}
{{192, 96, string1^2*string2^3*string3^2*string4^2, c^9, d^9}}

Surely you meant

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}};

Secondly, from what I can see, string1 (for instance) isn't a string, and c and d aren't integers. (They may be, but we have no indication of it from your post.)

Third, you mixed up the notations for Cases versus Select.

Either of these will work:

Cases[data,{1,_,_,_,_}]
{{1,1,string1,c,d},{1,2,string2,c,d},{1,3,string3,c,d},{1,4,string4,c,d}}

or

Select[data, First@# == 1 &]
{{1,1,string1,c,d},{1,2,string2,c,d},{1,3,string3,c,d},{1,4,string4,c,d}}

Bobby

On Sun, 13 Feb 2005 22:17:04 -0500 (EST), Hugo Mallinson <hfm21 at cam.ac.uk> wrote:

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

--
DrBob at bigfoot.com
www.eclecticdreams.net

```

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