Questions tagged [lubridate]

lubridate is an R package that makes it easier to work with dates and time objects.

The lubridate package facilitates working with dates and times in . lubridate also expands the type of mathematical operations that can be performed with date-time objects. It introduces three new time span classes borrowed from :

  • durations, which measure the exact amount of time between two points
  • periods, which accurately track clock times despite leap years, leap seconds, and day light savings time
  • intervals, a protean summary of the time information between two points

Repositories

Vignettes

Other resources

Related tags

2520 questions
12
votes
5 answers

Adding 15 business days in lubridate

I have a long list of start dates of a certain procedure. Rules require the procedure to be completed in, at most, 6 business days. I wish to compute the deadline. Using lubridate in R, I can get a six-day deadline thus > library(lubridate) >…
emagar
  • 985
  • 2
  • 14
  • 28
11
votes
2 answers

POSIXct object is NA, but is.na() returns FALSE

I have encountered some very peculiar behaviour in R. I think it might even be a bug, but I'm asking here to check if someone is familiar with it or knows a solution. What I'm trying to do is the following: I have a data frame with dates assigned to…
A. Stam
  • 2,148
  • 14
  • 29
11
votes
1 answer

R - lubridate - Convert Period into numeric counting months

Consider following: library(lubridate) period1 = weeks(2) as.numeric(period1, "weeks") > 2 # as expected Now I am trying to do similar with months: period2= months(6) as.numeric(period2, "months") as.numeric(period2, "weeks") > 26.08929 #…
Eric Lecoutre
  • 1,461
  • 16
  • 25
10
votes
4 answers

Length of lubridate interval

What's the best way to get the length of time represented by an interval in lubridate, in specified units? All I can figure out is something like the following messy thing: > ival [1] 2011-01-01 03:00:46 -- 2011-10-21 18:33:44 >…
Ken Williams
  • 22,756
  • 10
  • 85
  • 147
10
votes
1 answer

How to make a heatmap using time series data in R

I've been attempting to draw a heatmap using ggstructure. I don't mind using base graphics if I can get a few pointers. I want the heatmap to look similar to this: http://www.vistadatavision.com/uploads/images/reports/intensity_plot_1.PNG I haven't…
Chris
  • 1,888
  • 4
  • 21
  • 27
10
votes
1 answer

How to format a Date as "YYYY-Mon" with Lubridate?

I would like to create a vector of dates between two specified moments in time with step 1 month, as described in this thread (Create a Vector of All Days Between Two Dates), to be then converted into factors for data visualization. However, I'd…
Fabio Capezzuoli
  • 599
  • 7
  • 23
10
votes
1 answer

What does the lubridate note "method with signature ‘Timespan#Timespan’ chosen for function ‘%/%’" mean?

When I run the following code in R I get a strange note (it only appears the first time I run the code in a session): > library(lubridate) Attaching package: ‘lubridate’ The following object is masked from ‘package:base’: date Warning…
Tim
  • 225
  • 1
  • 9
10
votes
6 answers

Determine season from Date using lubridate in R

I have a very big dataset with a DateTime Column containing POSIXct-Values. I need to determine the season (Winter - Summer) based on the DateTime column. I've created a function which works fine on a small dataset, but crashes when I use it on the…
Ratnanil
  • 1,641
  • 17
  • 43
10
votes
5 answers

with_tz with a vector of timezones

I have a dataframe like so: library(dplyr) data <- data_frame( timestamp_utc = c('2015-11-18 03:55:04', '2015-11-18 03:55:08', '2015-11-18 03:55:10'), local_tz = c('America/New_York', 'America/Los_Angeles', …
josiekre
  • 795
  • 1
  • 7
  • 19
10
votes
1 answer

Extract week number from POSIXct object

Is there a function in lubridate to extract the week number? I've tried to search for that but couldn't find anything which serves the purpose. The week() function does something different. Description Date-time must be a POSIXct, POSIXlt, Date,…
Gianluca
  • 6,307
  • 19
  • 44
  • 65
10
votes
1 answer

Count number of days that time periods overlap

Using the lubridate library, I can find out if two time periods overlapped. But, is there an efficient way to compute for how many days they overlapped. (for instance how many days a women smoked while pregnant. The pregnancy period and smoking…
10
votes
1 answer

"parse_dt" not resolved from current namespace (lubridate)

I started getting this error message with the lubridate package: as.Date(ymd_hms("2014-1-1 12:31:15")) Error in .Call("parse_dt", x, format, TRUE) : "parse_dt" not resolved from current namespace (lubridate) I have never encountered this…
Remko Duursma
  • 2,741
  • 17
  • 24
10
votes
3 answers

Count the number of Fridays or Mondays in Month in R

I would like a function that counts the number of specific days per month.. i.e.. Nov '13 -> 5 fridays.. while Dec'13 would return 4 Fridays.. Is there an elegant function that would return this? library(lubridate) num_days <- function(date){ x…
vinchinzu
  • 604
  • 1
  • 7
  • 16
10
votes
6 answers

Convert dd/mm/yy and dd/mm/yyyy to Dates

I have some a character vector with dates in various formats like this dates <- c("23/11/12", "20/10/2012", "22/10/2012" ,"23/11/12") I want to convert these to Dates. I have tried the very good dmy from the lubridate package, but this does not…
Tom Liptrot
  • 2,273
  • 21
  • 23
9
votes
2 answers

Plot dates on the x axis and time on the y axis with ggplot2

I have read in a series of 37 dates and times that an event happened. It is now sitting as a POSIXlt object. I want a graphic representation of the times that the events happened on each day. So the x axis should be the date and y axis should be the…
Farrel
  • 10,244
  • 19
  • 61
  • 99