MathGroup Archive 2006

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

Search the Archive

Re: Conditions with Statistical Functions


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