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
9
votes
1 answer

Lubridate - Find overlap time between interval and a date

I have a dataframe with shift start and end in datetime format like so: shift_time <- data.frame( started_at = c("2019-09-01 02:00:00 AEST", "2019-09-02 05:00:00 AEST", "2019-11-04 20:00:00 AEDT"), ended_at = c("2019-09-01 11:30:00 AEST",…
userLL
  • 471
  • 5
  • 15
9
votes
3 answers

Joining two data frames with intervals misbehaves?

Edit (2019-06): This problem does not exist anymore, as this issue has been closed and a related feature implemented. If you now run the code with updated packages, it will work. I'm trying to find overlapping intervals and decided to join the…
pasipasi
  • 1,176
  • 10
  • 8
9
votes
1 answer

Using mutate with dates gives numerical values

I am using the lubridate and dplyr packages to work with date variables and to create a new date variable, respectively. library(lubridate) library(dplyr) Let df be my dataframe. I have two variables date1 and date2. I want to create a new variable…
HNSKD
  • 1,614
  • 2
  • 14
  • 25
9
votes
6 answers

Check if a date is within an interval in R

I have these three intervals defined: YEAR_1 <- interval(ymd('2002-09-01'), ymd('2003-08-31')) YEAR_2 <- interval(ymd('2003-09-01'), ymd('2004-08-31')) YEAR_3 <- interval(ymd('2004-09-01'), ymd('2005-08-31')) (in real life, I have 50 of…
Monica Heddneck
  • 2,973
  • 10
  • 55
  • 89
9
votes
5 answers

dplyr: grouping and summarizing/mutating data with rolling time windows

I have irregular timeseries data representing a certain type of transaction for users. Each line of data is timestamped and represents a transaction at that time. By the irregular nature of the data some users might have 100 rows in a day and…
divide_by_zero
  • 997
  • 1
  • 8
  • 20
9
votes
2 answers

How to create date from datetime (using lubridate)?

Assume I have created a variable containing date and time: a <- ymd_hms("2014-01-01 12:23:34") How do I create another variable that only has the date? That is, what should I do to transform a's value to be identical to b's value where b is b <-…
paljenczy
  • 4,779
  • 8
  • 33
  • 46
8
votes
3 answers

Converting Character Column to Date in R with Lubridate

I have a character column called date that holds data such as "January 15, 2015" I am trying to convert it to ymd format with the as.date function and I also tried the lubridate package. I have tried methods such as: shootings$Date <-…
Daniel Murran
  • 95
  • 2
  • 2
  • 7
8
votes
2 answers

lubridate 1.7.3 error: CCTZ: Unrecognized timezone of the input vector: ""

I have just installed the latest version of lubridate (1.7.3) and am getting the following error > x <- as.POSIXct("2014-06-01 08:21:59 BST") > for (j in 1:1e4){ dum <- lubridate::force_tz(x, tzone = 'UTC') } > for (j in 1:1e8){ dum <-…
user1165199
  • 6,351
  • 13
  • 44
  • 60
8
votes
5 answers

R: how to filter a timestamp by hour and minute?

I am struggling with the following example time = c('2013-01-03 21:59:21.549', '2013-01-04 22:00:21.549', '2013-01-05 22:01:21.222', '2013-01-06 22:06:23.559' ) value = c(1,2,3,4) data <- data_frame(time, value) data <-data %>% mutate(time =…
ℕʘʘḆḽḘ
  • 18,566
  • 34
  • 128
  • 235
8
votes
1 answer

Is there a fast parser for date

For datetimes fasttime provides very fast parsing to POSIXct library('fasttime') library('lubridate') library('microbenchmark') # parse character to POSIXct Sys.setenv(TZ='UTC') test <- rep('2011-04-02 11:01:00',1e4) microbenchmark( test1 <-…
statquant
  • 13,672
  • 21
  • 91
  • 162
8
votes
1 answer

Combining dplyr::mutate with lubridate::ymd_hms in R randomly causes segfault

I've searched as best I could for something related to this but haven't found anything on SO or dplyr github; possibly a new issue as the code below has worked fine prior to today? The problem is conceptually simple: calling my_data %>% mutate(x =…
John Sandall
  • 449
  • 6
  • 13
8
votes
2 answers

Looping through date in R loses format

This has been frustrating me. Even with lubridate I can't get dates to maintain their type when I loop over them. For example: require(lubridate) yearrange = ymd(20110101) + years(seq(4)) yearrange #[1] "2012-01-01 UTC" "2013-01-01 UTC" "2014-01-01…
beroe
  • 11,784
  • 5
  • 34
  • 79
8
votes
1 answer

Converting chr "00:00:00" to date-time "00:00:00"

My question comes from this question. The question had the following character string. x <- "2007-02-01 00:00:00" y <- "02/01/2007 00:06:10" If you try to convert this string to date-class object, something funny happens. This is a sample from…
jazzurro
  • 23,179
  • 35
  • 66
  • 76
8
votes
3 answers

Subtracting months - issue with last day of month?

Quick question on dates in R. Check out this snippet of code: Sys.Date() - months(3) # [1] "2013-12-31" Sys.Date() - months(18) # [1] NA I've loaded the package lubridate and followed the instructions provided , and I can't quite get my head around…
PMaier
  • 592
  • 7
  • 19
8
votes
2 answers

Parse dates in format dmy together with dmY using parse_date_time

I have a vector of character representation of dates, where formats mostly are dmY (e.g. 27-09-2013), dmy (e.g. 27-09-13), and occasionally some b or B months. Thus, parse_date_time in package lubridate that "allows the user to specify several…
Henrik
  • 65,555
  • 14
  • 143
  • 159