home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e032 / 3.ddi / FILES / STATISTI.PAK / MOVINGAV.M < prev    next >
Encoding:
Text File  |  1992-07-29  |  829 b   |  44 lines

  1.  
  2. (* Copyright 1988,1990 Wolfram Research, Inc. *)
  3.  
  4. (*:Version: Mathematica 2.0 *)
  5.  
  6. (*:Name: Statistics`MovingAverage` *)
  7.  
  8. (*:Author:
  9.         Wolfram Research, Inc. 
  10. *)
  11.  
  12. (*:Keywords: moving average *)
  13.  
  14.  
  15. (*:Requirements: none. *)
  16.  
  17. (*:Warnings: none. *)
  18.  
  19. BeginPackage["Statistics`MovingAverage`"]
  20.  
  21. MovingAverage::usage=
  22. "MovingAverage[list,n] returns a list of the n-th moving averages of list."
  23.  
  24. Begin["`Private`"]
  25.  
  26. Mean[list_List] := (Plus @@ list)/Length[list]
  27.  
  28. MovingAverage[list:{{_,_}..}, n_Integer] :=
  29. Block[{list1, list2},
  30.     {list1, list2} = Transpose[list];
  31.     Table[
  32.         {list1[[i+Floor[n/2]]], 
  33.         Mean[Take[list2,{i, i+n}]]}, 
  34.             {i,1, Length[list]-n}]
  35.     ]
  36.  
  37. MovingAverage[list_List, n_Integer] :=
  38.     Table[Mean[Take[list, {i, i+n}]], 
  39.         {i,1, Length[list]-n}]
  40.     
  41.     End[ ]
  42.  
  43.     EndPackage[ ]
  44.