       Re: Pure function in a pure function (again)

• To: mathgroup at smc.vnet.net
• Subject: [mg69818] Re: [mg69797] Pure function in a pure function (again)
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Sat, 23 Sep 2006 23:45:19 -0400 (EDT)

```data=Array[a,{15,5}];

Table[data[[n,1]]=Random[Integer,{1,5}],{n,Length[data]}];

Needs["Statistics`DataManipulation`"];

f[x_] := Plus@@Column[Select[data, #[] == x &], 2] ;

Given your description, presumably you meant

Plus@@f/@Range

a[1, 2] + a[2, 2] + a[3, 2] + a[6, 2] + a[9, 2] + a[14, 2]

This can be done without a helper function (and without the add-on package) as

Plus@@Cases[data,x_?(MemberQ[Range,#[]]&):>x[]]

a[1, 2] + a[2, 2] + a[3, 2] + a[6, 2] + a[9, 2] + a[14, 2]

%==%%

True

Bob Hanlon

---- Skirmantas Janusonis <janusonis at psych.ucsb.edu> wrote:
> Hello,
>
> I've already asked this question, but I thought there was a better way to state it. If Dat is a 2D-table, the following picks out the rows whose first element is 1,2 or 3 and adds up their the second elements:
>
> f[x_] := Plus @@ Column[Select[Dat, #[] == x &], 2]
> f /@ Range
>
> Instead of f/@Range, I'd like to use a second pure function, something like this:
>
> Map[Plus @@ Column[Select[Dat, #1[] == #2 &], 2]&,Range]
>
> This line is incorrect, however. How do I fix it?
>
> Thanks!
>
> Skirmantas
>

```

• Prev by Date: Re: Re: Extracting terms from an equation
• Next by Date: Re: Re: Extracting terms from an equation
• Previous by thread: Re: Pure function in a pure function (again)
• Next by thread: Re: Pure function in a pure function (again)