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: [mg66122] Re: Conditions with Statistical Functions
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Sun, 30 Apr 2006 04:21:24 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 4/29/06 at 3:40 AM, gregory.lypny at videotron.ca (Gregory Lypny)
wrote:

>Is it possible to attach conditions to statistical functions, for
>example, computing the mean of a list but only of the numbers that
>are bigger than 100?

The code below demonstrates a simple way of computing the mean for a set of random integers between 1 and 200 that are greater than 100.

In[7]:=
data=Table[Random[Integer,{1,200}],{1000}];
Mean[data]//N
Mean@Cases[data,_?(#>100&)]//N

Out[8]=
99.239

Out[9]=
150.678

If you wanted, you could unprotect the function Mean and add a new definition along the lines of

Mean[data_List, thres_?NumericQ]:= Mean@Cases[data, _?(#>thres&)]
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Illusory Multicore Support in 5.2?
  • Next by Date: Difference between the following integrals....
  • Previous by thread: Re: Conditions with Statistical Functions
  • Next by thread: Re: Conditions with Statistical Functions