Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*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 2006

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

Search the Archive

Re: Conditions with Statistical Functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66160] Re: [mg66091] Conditions with Statistical Functions
  • From: Gregory Lypny <gregory.lypny at videotron.ca>
  • Date: Tue, 2 May 2006 02:43:10 -0400 (EDT)
  • References: <2252055.1146367664201.JavaMail.root@eastrmwml01.mgt.cox.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Thanks again, Bob.

Nice use of pure pure functions (Is that what they're called?).   
Clearly, I have a long way to go in learning the syntax.  For  
example, I never would have thought of using a question mark between  
the x_List and VectorQ attribute because I'm still not up on what the  
question mark means in general.  Bits and pieces are falling into  
place though: I'm guessing that your use of the pound sign (#) in the  
second statement refers to any vector, whereas in my limited use of  
functions, such as Select, #[[1]] or #[[17]] would refer to the first  
and seventeenth columns.

	Greg

On Sat, Apr 29, 2006, at 11:27 PM, Bob Hanlon wrote:

> 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: "In progress" saving of data collected using Reap/Sow
  • Next by Date: Re: Conditions with Statistical Functions
  • Previous by thread: Re: Conditions with Statistical Functions
  • Next by thread: Re: Conditions with Statistical Functions