Re: [R] Calculating date difference in days

2019-05-22 Thread Jeff Newmiller
At the point where you say "date difference in days" IMO you have departed from what `difftime` is for and are in the realm of a numeric measure. I ignore the units inside `difftime` at all times and convert to numeric with a units argument if I want to be that specific about how the measure is

Re: [R] Calculating date difference in days

2019-05-22 Thread William Dunlap via R-help
You can use units<- to change the time units of the difference. E.g., > d <- as.POSIXlt("2018-03-10") - as.POSIXlt("2018-03-09 02:00:00") > d Time difference of 22 hours > units(d) <- "days" > d Time difference of 0.917 days > > units(d) <- "mins" > d Time difference of 1320 mins > units(d)

Re: [R] Calculating date difference in days

2019-05-22 Thread Boris Steipe
ed <- as.POSIXlt("2018-03-10") sd <- as.POSIXlt("2018-02-10") as.numeric(ed-sd) [1] 28 ed <- as.POSIXlt("2000-03-10") sd <- as.POSIXlt("2000-02-10") as.numeric(ed-sd) [1] 29 Cheers, B. > On 2019-05-22, at 17:43, reichm...@sbcglobal.net wrote: > > R Help > > I have a function to calculate a

[R] Calculating date difference in days

2019-05-22 Thread reichmanj
R Help I have a function to calculate a date difference in days but my results come back in hours. I suspect I am using the as.POSIXlt function incorrectly . Suggestions? # Start time of data to be considered start_day <- "2016-04-30" # Make event and sequence IDs into factors elapsed_days