MathGroup Archive 2007

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

Search the Archive

Re: Means


JGBoone at gmail.com wrote:
> I was wondering if anyone knew how to take the mean of only half of a
> paired order. I have a table of 3000 pairs and want to take the
> average of the last half of the last number in the pair. I do this by
> N[Mean[Map[Last, list]]] is there any way to map to the last half of
> the list. Thanks

You could use Take with a negative second argument as in the following:

In[1]:=
list = Table[{Random[], Random[Integer, 10]}, {20}]

Out[1]=
{{0.134179, 2}, {0.122422, 8}, {0.540121, 5},
   {0.490495, 7}, {0.97891, 4}, {0.458892, 4},
   {0.698429, 1}, {0.549347, 6}, {0.214567, 9},
   {0.670112, 10}, {0.118525, 2}, {0.754165, 7},
   {0.2386, 6}, {0.233337, 1}, {0.838034, 7},
   {0.126505, 9}, {0.597379, 8}, {0.469553, 1},
   {0.405691, 3}, {0.845892, 0}}

In[2]:=
N[Mean[Last /@ Take[list, -10]]]

Out[2]=
4.4

In[3]:=
N[Mean[Last /@ Take[list, -Length[list]/2]]]

Out[3]=
4.4

Regards,
Jean-Marc


  • Prev by Date: Re: The Mathematica equivalent of Cons (as in Lisp)?
  • Next by Date: Re: Parse results from Solve
  • Previous by thread: Re: Means
  • Next by thread: Re: Re: Means