[R] Missing data?
rkevinburton at charter.net
Tue Nov 22 23:13:52 CET 2011
Thank you for the suggestions.
The only problems I see with 'to.weekly' is converting from the OHLC format
and realizing that the date is the last day of the week rather than the
first day of the week. Very minor compared to doing the whole thing myself.
From: R. Michael Weylandt <michael.weylandt at gmail.com>
[mailto:michael.weylandt at gmail.com]
Sent: Tuesday, November 22, 2011 3:10 PM
To: Kevin Burton
Cc: <r-help at r-project.org>
Subject: Re: [R] Missing data?
Couldn't you use seq.Date() to set up the time index and then just fill as
Alternatively, to.weekly if you are starting with a daily series.
On Nov 22, 2011, at 4:00 PM, "Kevin Burton" <rkevinburton at charter.net>
> I was wondering what the best approach is for missing data in a time
> I give an example using xts but I would like to know what seems to be
> the "best" method. Say I have
> xts.ts <- xts(1:4,as.Date(c("1970-01-01", "1970-1-3", "1980-10-10",
> "2007-8-19")), frequency=52)
> I would like to turn this into a time series (still could be xts, or
> converted to ts) that has values for every week starting with the week
> that includes the start date and ending with the week that includes the
> If there is data for the week then use it otherwise set it to NA or 0.
> Remember some years have 52, 53, or rarely 54 full or partial weeks.
> What to do with the partials at the beginning and ending of the year?
> This seems to be a fairly common problem and doing it myself is very
> cumbersome. Does a solution to this kind of problem exist? Once the
> approach to a weekly period is found I am sure that adjustment to
> daily, monthly, or quarterly would be relatively straightforward.
> Thank you.
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help