Search code examples
statisticswolfram-mathematica

How to choose values from a list. Mathematica


I have this code:

    x = {1, 2, 3, 4, 5}; p = {0.5, 0.3, 0.1, 0.06, 0.04};
Do[
 n = RandomVariate[PoissonDistribution[30]]; M = Table[0, {n}];
 Do[
  U = RandomReal[]; i = 1;
  While[U > Sum[p[[j]], {j, 1, i}], i = i + 1];
  X = x[[i]]; M[[j]] = X;
  , {j, 1, n}];
 Daytotal[k] = M
 , {k, 1, 365}]
W = Table[Total[Daytotal[m]], {m, 1, 365}];
N[Mean[W]]
Histogram[W, Automatic, "PDF"]

And i wanna choose from W the values that is greater than 80. I've tried everything i know with command While, but i can't find a result.


Solution

  • Either

    greaterthan80={};
    i=1;
    While[i<=365,
      If[W[[i]]>80,
        AppendTo[greaterthan80,W[[i]]]
      ];
      i++
    ];
    greaterthan80
    

    or

    isitgreater[x_]:=x>80;
    greaterthan80=Select[W,isitgreater]
    

    or just

    greaterthan80=Select[W,#>80&]