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

Calculating the number of days since most recent visit or baseline in R (in a dataset with a varying number of repeated instances)

data <- data.frame( record_id = c(1,1,1,2,3,4,4,5,6,7,8,8,9,10,10,10), visit_date = c("2020-09-24", "2020-12-05", "2021-03-01", "2021-10-03", "2021-10-01", "2021-10-05", "NA", "2021-08-25", "2021-09-19", "2021-10-01", "2021-09-27", "2021-09-07",…
0
votes
1 answer

Using dplyr and mutate to categorize a new variable in R

record_id <- c(1,1,1,2,3,4,4,5,6,7,8,8,9,10,10,10) visit_date <- c("2018-09-24", "2018-12-05", "2019-03-01", "2018-10-03", "2018-10-01", "2018-10-05", "NA", "2018-08-25", "2018-09-19", "2018-10-01", "2018-09-27", "2021-09-07", "2018-10-03",…
0
votes
1 answer

Calculate duration between two events with filters from another variable in R

I have a df where I need to calculate the number of days between two types of events among a long list of possible events, say an overdose 'A_type_event' and a clinical session 'C_type_event' for a given unique id where event A always precedes event…
0
votes
1 answer

Library (Lubridate)

I am having a problem with the package Lubridate in R. I can install the package, but when I go to call the library(lubridate) I keep getting the error message below. "Attaching package: ‘lubridate’ The following objects are masked from…
Cole
  • 23
  • 4
0
votes
0 answers

Not able to round date to nearest hour in R tried lubridate, strptime, and POSIXCT

Following is an example of the column of the data frame time 00:01:47 01:05:45 17:10:00 20,551,697 more rows The data type is character The data is from Citi Bikes New York for the period January 2019 to December 2019 Note: the data…
0
votes
1 answer

How do I correctly analyze and plot my hotel booking data in R?

I'm a beginner learner in R and my data is the data of a hotel with 3 different apartments and its bookings between 2018 and 2022. For each booking I have an arrival date and a departure date (already in the date format), the total nights booked and…
Sofia
  • 21
  • 3
0
votes
0 answers

Trying to for loop the parse_date_time() for specific dataframes

I am still relatively new to R and any tips would be appreciated So I want to parse the time for specific dataframes and what I've tried to do was create a list and adjust the names accordingly. mydir = "Data/Fitabase_Data_4.12.16-5.12.16" csvfiles…
DNW78
  • 1
  • 2
0
votes
0 answers

I get 'R Session Aborted' when installing any package in RStudio

When I try to install a package, I get the following message on RStudio install.packages("lubridate") R Session Aborted EDIT : It does work in RGui though --- Please select a CRAN mirror for use in this session --- trying URL…
Julien
  • 1,613
  • 1
  • 10
  • 26
0
votes
1 answer

R/Lubridate is reading my Date-Time wrong

Source .csv file is here: https://divvy-tripdata.s3.amazonaws.com/index.html (Just Jul 2021 will do as an example month. My eventual goal is to get the difftime between started_at and ended_at , and assign a calendar-day of the week to each…
0
votes
3 answers

Generate date sequence by months

This is the result I want: library(lubridate) res <- structure( c( 16160, 16251, 16343, 16435, 16525, 16616, 16708, 16800, 16891, 16982, 17074, 17166, 17256, 17347, 17439, 17531, 17621, 17712, 17804, 17896, 17986, 18077, 18169,…
Mwavu
  • 1,826
  • 6
  • 14
0
votes
1 answer

Conversion of a duration between two dates in lubridate does not work

I am trying to convert a duration between 2 dates in days with lubridate package in R and getting some error messages. I tried the following codes: tbls_data_new1<- tbls_data_new %>% mutate(days = interval(end,start), …
0
votes
1 answer

Character to Date

I am having some problems with changing dates from Excel (characters in R) into date in R. Knowing that I am using : as.Date(Data$Datum, "d%/m%/y%") But it returns NA NA NA.. And the date starts in Excel on : 1-1-2019 , but in R it shows : "43466" I…
A.A
  • 15
  • 3
0
votes
2 answers

Recursive filtering in R

I have data I need to clean, but not sure how. I need to remove all records that occured less than 7 days after the last observation, excluding those that need to be removed. Data example: library(dplyr) library(lubridate) df = data.frame(id =…
Darmist
  • 50
  • 9
0
votes
0 answers

Group rows by time interval in R

I have the following part of my data: test <- wrapr::build_frame( "date_time" , "automatic", "validate" | "2020-12-01 00:34:58", "sombra" , "sombra" | "2020-12-01 00:34:59", "organismo", "sombra" | "2020-12-01…
Wilson Souza
  • 830
  • 4
  • 12
0
votes
1 answer

Given two intervals, how to return logical true false if intervals overlap?

I'm trying to work out whether two different date ranges overlap and return a TRUE/FALSE where they do, which will allow me to successfully filter the data I'm interested in. I was trying to use lubridate intervals and the %within% which basically…
Dasr
  • 777
  • 6
  • 16
1 2 3
99
100