0
$\begingroup$

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?

$\endgroup$
3
  • 1
    $\begingroup$ Welcome to SE! It will help those might answer if you would please post code that is syntactically correct and properly formatted. See editing help. $\endgroup$
    – Michael E2
    Jan 23 '14 at 12:49
  • $\begingroup$ This should be helpful: Using the result of Solve in subsequent calculations, together with Mean. $\endgroup$
    – Michael E2
    Jan 23 '14 at 12:51
  • $\begingroup$ @JacobAkkerboom Sorry, it was involuntary. Please rollback my edit to yours if think it better. (or merge both!) $\endgroup$ Jan 23 '14 at 13:08
5
$\begingroup$
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}}]
$\endgroup$
3
$\begingroup$

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
$\endgroup$
3
$\begingroup$

[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

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.