[R] Missing data?

R. Michael Weylandt <michael.weylandt@gmail.com> michael.weylandt at gmail.com
Tue Nov 22 22:09:42 CET 2011


Couldn't you use seq.Date() to set up the time index and then just fill as appropriate?

Alternatively, to.weekly if you are starting with a daily series. 

Michael

On Nov 22, 2011, at 4:00 PM, "Kevin Burton" <rkevinburton at charter.net> wrote:

> I was wondering what the best approach is for missing data in a time series.
> I give an example using xts but I would like to know what seems to be the
> "best" method. Say I have
> 
> 
> 
> library(xts)
> 
> 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 end date.
> 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.
> 
> 
> 
> Kevin
> 
> 
> 
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list