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
6
votes
2 answers

How to get a date from day of year

I am working with a data set that looks a bit like this: Year Date Day_nr Value 1976 19-02-1976 50 167 1976 19-03-1976 79 140 1978 05-03-1978 64 200 1978 05-04-1978 95 200 1999 05-05-1999 125 89 …
Sarina
  • 548
  • 3
  • 10
6
votes
2 answers

French names using wday in lubridate

The wday() function in the lubridate package with the option label = TRUE returns the name of the day of the week in English. I'd like to know if it is possible to get the name of day of the week in another language. Is there any option for that ?
PAC
  • 5,178
  • 8
  • 38
  • 62
6
votes
1 answer

In R, how do I output a lubridate compatible date in yyyymmdd format? The equivalent of .ToString("yyyyMMdd") in .NET?

In R, I can parse a date into Lubridate format using: d <- ymd("2013-02-15") How do I output this in yyyyMMdd format, e.g.: 20130215 The equivalent .NET command would be: .ToString("yyyyMMdd") I know the answer to this will be simple, but I've…
Contango
  • 76,540
  • 58
  • 260
  • 305
6
votes
2 answers

function naming conflicts

What are some good patterns for development with packages that define the same function? In my case, lubridate and data.table both define wday.
Sim
  • 13,147
  • 9
  • 66
  • 95
5
votes
3 answers

Transforming complete age from character to numeric in R

I have a dataset with people's complete age as strings (e.g., "10 years 8 months 23 days) in R, and I need to transform it into a numeric variable that makes sense. I'm thinking about converting it to how many days of age the person has (which is…
Ruam Pimentel
  • 1,288
  • 4
  • 16
5
votes
1 answer

R Lubridate dmy output format

I'm working with Lubridate package for formatting the dates in my data. str(base$date) #> chr [1:38] " 23.09.2020 " " 23.09.2020 " " 17.06.2020 " " 03.06.2020 " ... base$date <-dmy(base$date) str(base$date) #> Date[1:38],…
user17465205
  • 53
  • 1
  • 4
5
votes
2 answers

Efficiently find the overlap between two time intervals in R

I have used combn() to find the overlap between two dates/times using lubridate package. But combn() is too slow to process the large dataset I am working on. I am trying to use comboGeneral() from RcppAlgos package but I can't get it to work. Any…
Zaw
  • 1,434
  • 7
  • 15
5
votes
2 answers

count the number of days between two dates per year

I have a dataframe with a start and end date for each row. I would like to calculate the number of days between the two dates and split it by year. So going from this: id <- c(1,2,3) start <- as.Date(c('01/01/2015','01/01/2016','07/01/2015'), format…
Romain
  • 171
  • 11
5
votes
1 answer

Converting `dttm` to `date` formatting with as.Date and as_date give different results in R

I have a large data set with individual columns for event times and dates. I ended up creating a master dttm object with both the times and dates together, but have had trouble when I try to filter based on the date. Here is a sample data set that…
Trent
  • 771
  • 5
  • 19
5
votes
2 answers

Mutate_if or mutate_at in dplyr with Dates

I have a data set that is over 100 columns, but for example lets suppose I have a data set that looks like dput(tib) structure(list(f_1 = c("A", "O", "AC", "AC", "AC", "O", "A", "AC", "O", "O"), f_2 = c("New", "New", "New", "New", "Renewal",…
akash87
  • 3,876
  • 3
  • 14
  • 30
5
votes
2 answers

Parsing complicated date column

I have a date column that contains dates public opinion polls occur. These polls occasionally run over several days (usually but not always continuously), the polls sometimes start in one month and finish in the next, and the year has occasionally…
Emily Kothe
  • 842
  • 1
  • 6
  • 17
5
votes
2 answers

Reverse ggplot time scale

I am creating a timetable plot to show how many events are in each time block. I have calculated all this information from lubridate and can plot it on ggplot fine. But I need to reverse/flip the axis so that the top shows 8am and goes down to 5pm…
Sahir Moosvi
  • 549
  • 2
  • 21
5
votes
1 answer

Finding the min or max of POSIXct date with NA values

The data below has columns for an individual ID (with repeat observations), Date and Fate. ID Date Fate 1 BHS_1149 2017-04-11 MIA 2 BHS_1154 3 BHS_1155 4 BHS_1156 5 BHS_1157 …
B. Davis
  • 3,391
  • 5
  • 42
  • 78
5
votes
1 answer

fill sequence of datetimes

I have a data.frame consisting of IDs, DateTimes and Values. For each ID I want to expand the DateTimes so that there is one every hour between the min and max. The ID and Value columns should be filled with their respective values (i.e. not NA).…
sebdalgarno
  • 2,929
  • 12
  • 28
5
votes
1 answer

Interval class in data.table

My question will be explained throughout the following reproducible example. First, let's load the required packages and create a POSIXct and a data.table object. library(data.table) library(lubridate) target_date <- ymd(20180601,…
J.P. Le Cavalier
  • 1,315
  • 7
  • 16