Re: [R] Find missing days

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed, 2 Jan 2008 02:21:51 -0500

Try this. It creates a sequence of dates from the range of df$date1 and then does a setdiff between that and the original dates. The result is numeric so we create a Date structure out of it.

structure(setdiff(do.call(seq, as.list(range(df$date1))), df$date1), class = "Date")

On Jan 2, 2008 1:55 AM, <Lauri.Nikkinen_at_veripalvelu.fi> wrote:
> Hi,
>
> I have a data.frame like this:
>
> y <- rnorm(60)
> lev <- gl(3,20, labels=paste("lev", 1:3, sep=""))
> date1 <- as.Date(seq(ISOdate(2007,9,1), ISOdate(2007,11,5),
> by=60*60*24))
> date1 <- date1[-c(3,4,15,34,38,40)]
> df <- data.frame(lev=lev, date1=date1, y=y)
>
> I would like to produce a new data.frame with missing days in df$date1
> in each df$lev, like this:
>
> lev date1
> 1 lev1 2007-09-03
> 2 lev1 2007-09-04
> 3 lev1 2007-09-15
> 4 lev2 2007-09-01
> 5 lev2 2007-09-02
> etc.
>
> How can I do this?
>
> Thanks,
> Lauri
> FRCBS
>
>
>
> [[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.
>



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. Received on Wed 02 Jan 2008 - 07:25:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 02 Jan 2008 - 08:30:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive