MathGroup Archive 2006

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

Search the Archive

Re: Conditions with Statistical Functions


conditionalMean[x_List?VectorQ, cond_Function]:=
    Mean[Select[x,cond]];

conditionalMean[x_List, cond_Function]:=
    conditionalMean[#,cond]&/@Transpose[x];

m=Table[Random[Integer,200],{4},{3}]

{{12, 138, 117}, {92, 13, 178}, {147, 131, 123}, {34, 177, 109}}

Mean/@m

{89, 283/3, 401/3, 320/3}

Mean[m]

{285/4, 459/4, 527/4}

conditionalMean[#,(#>100)&]&/@m

{255/2, 178, 401/3, 143}

conditionalMean[m,(#>100)&]

{147, 446/3, 527/4}


Bob Hanlon


---- Gregory Lypny <gregory.lypny at videotron.ca> wrote: 
> Yes, thanks Bob.  But what about a matrix, where Mean operates column- 
> wise?  Is there a compact statement where the mean will be calculated  
> over the values that exceed 100 in each column all in one shot?  What  
> I've been doing is looping Select across the columns using Do and  
> applying Mean on each pass.  I just thought there might be something  
> more efficient, if not more elegant.
> 
> Regards,
> 
> 	Greg
> 
> On Sat, Apr 29, 2006, at 6:53 AM, Bob Hanlon wrote:
> 
> > x={10,20,150,200,250};
> >
> > Mean[Select[x,#>100&]]
> >
> > 200
> >
> >
> > Bob Hanlon
> >
> 


  • Prev by Date: Re: 3D plot with range restricted to non-rectangular region
  • Next by Date: Re: 3D plot with range restricted to non-rectangular region
  • Previous by thread: Re: Conditions with Statistical Functions
  • Next by thread: Calling .exe with Run