Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find day of year with the lubridate package in R

Tags:

r

lubridate

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.

like image 549
Joshua Rosenberg Avatar asked Dec 09 '15 21:12

Joshua Rosenberg


People also ask

How do I get weekday in Lubridate?

Value. wday() returns the day of the week as a decimal number or an ordered factor if label is TRUE .

What is the Lubridate package in R?

Lubridate is an R package that makes it easier to work with dates and times. Below is a concise tour of some of the things lubridate can do for you. Lubridate was created by Garrett Grolemund and Hadley Wickham, and is now maintained by Vitalie Spinu.

What is the use of Lubridate package?

lubridate: Make Dealing with Dates a Little EasierFunctions to work with date-times and time-spans: fast and user friendly parsing of date-time data, extraction and updating of components of a date-time (years, months, days, hours, minutes, and seconds), algebraic manipulation on date-time and time-span objects.

How do I use year function in R?

To get the year from a date in R you can use the functions as. POSIXct() and format() . For example, here's how to extract the year from a date: 1) date <- as. POSIXct("02/03/2014 10:41:00", format = "%m/%d/%Y %H:%M:%S) , and 2) format(date, format="%Y") .


1 Answers

The correct function is yday, as in

lubridate::yday(Sys.time()) 
like image 121
Jesse Anderson Avatar answered Oct 23 '22 14:10

Jesse Anderson