| To: | "s-news" <s-news@lists.biostat.wustl.edu> |
|---|---|
| Subject: | Eliminating NA's in a Time Series |
| From: | "Paul Lasky" <phlasky@earthlink.net> |
| Date: | Tue, 17 Aug 2004 12:24:45 -0700 |
| Reply-to: | phlasky@earthlink.net |
|
Thanks to Pat Burns, Tony Plate, Chuck Taylor ---Insightful, Prof Erin Hodgess ---Univ of Houston, John Walker, & Prof. Eric Zivot --- Univ of Wash for their help on this problem.
Chuck offered the thought "There really ought to be a method for this, but there isn't one." His solution and Tony's focus on the idea that a time series is basically just an object containing a "positions" slot and a "data" slot. To solve the problem : 1) extract the data slot , 2) remove the NA's from the data slot just as you would do with a matrix, then 3) recombine.
Here's Tony's neat solution:
First generate a test time Series:
TS = timeSeries(data="">> TS
Positions 1 2 01/02/2004 3 NA 01/09/2004 5 2 01/16/2004 4 5 01/23/2004 3 1 . . . etc. Then:
TS.clean = TS [ rowSums ( is.na ( seriesData( test.TS ) ) = = 0 ) , ]
In other words to my surprise, it works to just test for the NA's in the data slot just as you would for a matrix row then simply put the test back into the "row" part of the entire time series. Chuck's idea was similar:
which.na = apply ( TS@data, 1, FUN = function ( x ) any ( is.na(x) )
TS.clean = TS[ ! which.na ]
Frankly I don't know why putting the "which.na" into a brackets WITHOUT a comma works, but it does !
I tried a cute idea using seriesMerge, which worked, but frankly I can't repeat it ! Also Prof. Zivot suggested using the
seriesMerge function.
Working on this problem really helped me understand time Series which are quite tricky to manipulate even with the invaluable help of Prof. Zivot's book, "Modeling Financial Time Series with S-Plus."
Paul Lasky
P & B Consultants.
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: Histograms on same scale, Sundar Dorai-Raj |
|---|---|
| Next by Date: | a question about Splus output, fu_xin |
| Previous by Thread: | Eliminating NA's in a Time Series, Paul Lasky |
| Next by Thread: | What does this LME error mean?, Eric Lim |
| Indexes: | [Date] [Thread] [Top] [All Lists] |