[R] Count days of current year

Gabor Grothendieck ggrothendieck at gmail.com
Tue Nov 25 14:20:05 CET 2008


As yearmon represents year/month as year + fraction of year
adding 1 gives next year.  The first output below
gives an answer of class "difftime" whereas the the second
solution is "numeric":

> library(zoo)
> year <- 2000:2010
> d <- as.Date(as.yearmon(year)+1) - as.Date(as.yearmon(year))
> d
Time differences in days
 [1] 366 365 365 365 366 365 365 365 366 365 365

> # or to get a numeric answer:
> as.double(d, units = "days")
 [1] 366 365 365 365 366 365 365 365 366 365 365



On Mon, Nov 24, 2008 at 2:25 PM, Felipe Carrillo
<mazatlanmexico at yahoo.com> wrote:
> Hi:
> Is there a function that counts the number of days of any given or current year based on the date?
>
> Felipe D. Carrillo
> Supervisory Fishery Biologist
> Department of the Interior
> US Fish & Wildlife Service
> California, USA
>
> ______________________________________________
> 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