Find day of year with the lubridate package in R

Joshua Rosenberg picture Joshua Rosenberg · Dec 9, 2015 · Viewed 9.7k times · Source

I'm looking to find the day of year for a POSIXct class object with lubridate. For example, 12-9-2015 is day 343.

It's easy to find the day of the week or month with lubridate:

> lubridate::wday("2015-12-09 04:27:56 EST", labels = T)
Wed
> lubridate::day("2015-12-09 04:27:56 EST")
9

Is there an easy way to do so for the day of the year? I've searched the documentation and other questions but have not (yet) found an answer.

Answer

blindjesse picture blindjesse · Dec 9, 2015

The correct function is yday, as in

lubridate::yday(Sys.time())