0

How can we find the mean of the following type of data?

{{β -> 0.516819}, {β -> 0.499907}, 
 {β -> 0.494064}, {β -> 0.472742}, 
 {β -> 0.537485}, {β -> 0.478291}, 
 {β -> 0.523855}, {β -> 0.483624}, 
 {β -> 0.50126},  {β -> 0.527267}}

Which command could be used to find the mean of this data?

Öskå
  • 8,587
  • 4
  • 30
  • 49

3 Answers3

5
Mean[beta /. {{beta -> 0.516819}, {beta -> 0.499907}, {beta -> 
     0.494064}, {beta -> 0.472742}, {beta -> 0.537485}, {beta -> 
     0.478291}, {beta -> 0.523855}, {beta -> 0.483624}, {beta -> 
     0.50126}, {beta -> 0.527267}}]
ciao
  • 25,774
  • 2
  • 58
  • 139
3

[Beta] is bad syntax, so i replaced all by beta

Mean[{{beta->0.516819},{beta->0.499907},{beta->0.494064},{beta->0.472742},
{beta->0.537485},{beta->0.478291},{beta->0.523855},{beta->0.483624},{beta->0.50126},
{beta->0.527267}}[[All,1,2]]]

If you want the variance, try opening the documentation and search for it

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
Coolwater
  • 20,257
  • 3
  • 35
  • 64
3

Considering the votes, I think Timings are in order.

Double semicolons are intentional, they prevent extra memory use when $HistoryLength > 1

Timing comparison between other answers

nn = 1*^6;
rands = RandomReal[1, nn]; ;
data = {b -> #} & /@ rands; ;

Mean@data[[All, 1, 2]] // Timing
Mean@(b /. data) // Timing

Outputs

{0.069164, 0.500199}
{0.983088, 0.500199}

Perhaps also noteworthy

<<Developer`
data[[All, 1, 2]] // PackedArrayQ
(b /. data) // PackedArrayQ

Outputs

False
False
Jacob Akkerboom
  • 12,215
  • 45
  • 79