Questions tagged [difftime]

A function in R that calculates the difference of two times.

A function in that calculates the difference of two times.

is a function in that provides creation, printing and some arithmetic for calculating time intervals or time differences.

The signature of is as follows:

difftime(time1, time2, tz, units = c("auto", "secs", "mins", "hours", "days", "weeks"))

See official documentation for more details.

181 questions
0
votes
1 answer

as.difftime() from string

The result of the following instruction: as.difftime("5 11:04:36", "%d %H:%M:%S", units =("mins")) is Time difference of -7975.4 mins It seems that this function is calculating the time difference between Sys.Time() and the given value. I actually…
michele74c
  • 63
  • 11
0
votes
1 answer

Difference between dates not a whole number

Why is this not giving me a whole number of days? difftime("2015-04-22", "2014-10-30") Time difference of 173.9583 days
ChrisP
  • 119
  • 1
  • 8
0
votes
1 answer

how to handle incorrect value of difftime() function in R?

I have dataframe and there two columns of 1st_date date and 2nd_date. I used difftime() function to calculate the difference by days, and it did the job. However, I found an incorrect value when I checked all values generated by difftime() The…
0
votes
2 answers

Conditionally Perform difftime in R

I have a data table with devices that are inspected "annually." When the device has an inspection code "AC" (inspection_disposition_cd="AC"), then I need to count the days passed since the inspection record listed in the row directly above it. The…
few fda
  • 1
  • 2
0
votes
2 answers

Check time_t variable initialized

How to check if a time_t variable is initialized? If I want to compute the difference of two time_t vars with the difftime function, do I need to manually perform any sanity checks before invokation? Also, since the difftime return value is a…
alex
  • 121
  • 3
  • 9
0
votes
1 answer

Time period between dates in R

I have a data frame with Id Column & Date Column. Essentially, I would like to create a third column (Diff) that calculates the difference between dates, preferably grouped by ID. I have constructed a large POSIXlt from the following code c_time…
Samuel Ellett
  • 37
  • 1
  • 1
  • 4
0
votes
1 answer

Creating a new column which gives the difference in time between two other columns in condition to another column in R

My data is like this. df is the name of the dataframe Status ArrivalDate ClosedDate Closed 2015-12-01 04:40:24 2015-12-08 10:12:08 In Progress 2015-12-03 06:40:00 Pending 2015-12-12…
0
votes
2 answers

looping over rows with difftime

I have a column of times under timefact > head(foo) cnrd_marsh timefact timefact_hour 1 БЧ 2016-04-07 14:34:00 14 2 БЧ 2016-04-07 14:15:00 14 3 БЧ 2016-04-07 14:10:00 14 4 …
iskandarblue
  • 7,208
  • 15
  • 60
  • 130
0
votes
1 answer

iterating difftime over consecutive rows with conditions

I have a column of times in timefact > head(foo) cnrd_marsh timefact timefact_hour 1 БЧ 2016-04-07 14:34:00 14 2 БЧ 2016-04-07 14:15:00 14 3 БЧ 2016-04-07 14:10:00 14 4 БЧ…
iskandarblue
  • 7,208
  • 15
  • 60
  • 130
0
votes
1 answer

time difference of consecutive rows with condition

I have a list of times: > sapply(copy, class) $timefact [1] "POSIXct" "POSIXt" $timefact_hour [1] "integer" > head(copy) timefact timefact_hour 1 2016-04-07 23:42:00 23 2 2016-04-07 23:37:00 23 3 2016-04-07…
iskandarblue
  • 7,208
  • 15
  • 60
  • 130
0
votes
1 answer

R timediff - 22-JAN-16 04.56.14.325000000 PM

I want to calculate the duration between 2 date of a data frame which formatted as per below: Start_date_time 22-JAN-16 04.56.14.325000000 PM End_date_time 23-JAN-16 05.56.14.325000000 AM I run the below command: jm16$diff <-…
user2778168
  • 193
  • 9
0
votes
0 answers

How to either calculate with POSIXlt or convert POSIXlt class into POSIXct in R?

I was trying to find an answer to my question as mentioned above. I am trying to calculate the minutes difference between datetime formated cells in two separate columns. However, the input is already in POSIXlt and it seams (for me also…
0
votes
1 answer

Difftime for workdays according to holidayNYSE in R

I'm trying to find difftime for working days only. I want to calculate difftime according to holidayNYSE calendar. When I use the difftime function weekends and holidays are included in the answers, my dataset contaies only data from working days,…
M.O
  • 1
  • 2
0
votes
1 answer

How to add time (not minutes/seconds etc, just time E.g., 17:30:00) for one particular day to a list of POSIXct dates in R?

I have a data that consists of date and time which are in POSIXct format as shown below : > DayandTime date_time 1 2015-10-01 11:13:25 2 2015-10-01 12:38:09 3 2015-10-01 17:12:00 4 2015-10-02 11:44:05 5 2015-10-05 13:45:07 6 …
sunitprasad1
  • 768
  • 2
  • 12
  • 28
0
votes
1 answer

get time diff for each group in R

If I have some data like this. 1 A 02-01-2015 08:08:00 1 B 02-01-2015 08:11:00 1 C 02-01-2015 08:12:00 1 D 02-01-2015 08:16:00 2 A 02-01-2015 09:08:00 2 B 02-01-2015 09:11:00 2 C 02-01-2015 09:13:00 2 D …
DK2
  • 651
  • 1
  • 7
  • 34