home *** CD-ROM | disk | FTP | other *** search
-
- (* Copyright 1988,1990 Wolfram Research, Inc. *)
-
- (*:Version: Mathematica 2.0 *)
-
- (*:Name: Statistics`MovingAverage` *)
-
- (*:Author:
- Wolfram Research, Inc.
- *)
-
- (*:Keywords: moving average *)
-
-
- (*:Requirements: none. *)
-
- (*:Warnings: none. *)
-
- BeginPackage["Statistics`MovingAverage`"]
-
- MovingAverage::usage=
- "MovingAverage[list,n] returns a list of the n-th moving averages of list."
-
- Begin["`Private`"]
-
- Mean[list_List] := (Plus @@ list)/Length[list]
-
- MovingAverage[list:{{_,_}..}, n_Integer] :=
- Block[{list1, list2},
- {list1, list2} = Transpose[list];
- Table[
- {list1[[i+Floor[n/2]]],
- Mean[Take[list2,{i, i+n}]]},
- {i,1, Length[list]-n}]
- ]
-
- MovingAverage[list_List, n_Integer] :=
- Table[Mean[Take[list, {i, i+n}]],
- {i,1, Length[list]-n}]
-
- End[ ]
-
- EndPackage[ ]
-