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

R difftime define units to use

I'm trying to calculate the time of various processes but they vary between 10 seconds and ten minutes and I'd like them to be in common terms (ie all minutes). When I run this code I would expect it to returns in minutes but it returns in…
screechOwl
  • 27,310
  • 61
  • 158
  • 267
-1
votes
1 answer

Rounding the mean of difftime

In my R data.table mdt below, I have calculated a difference in dates using subtraction (simple mathematical expression) as days_elapsed1 and days_elapsed2. The class of these two objects is "difftime" expressed in days. Then, I take the mean of…
sunflower
  • 3
  • 2
-1
votes
1 answer

R difftime() producing incorrect intervals

The data was imported from a CSV file, with the dates originally in characters. I have mutated them separately as I want to do some further analysis on them. The only other question on the topic I can find, the answer is complicated by needing to…
Pendragon
  • 119
  • 9
-1
votes
1 answer

Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard unambiguous format in difftime function

I am applying difftime function on the columns started_at and ended_at and the data type of both columns is "character" but i am getting the following error. Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard…
-1
votes
1 answer

Trying to get the time difference between two time points in R. I have NAs in the data set and i cant find a way to do it correctly

My data is currently in two separate columns T1 example looks like 2020-05-01 09:00:00 PM T2 example took like 2020-05-02 04:00:00 AM This data also contains NAs Data mode and class is characters I would like to know the difference between these in…
dipcup
  • 11
  • 1
-1
votes
1 answer

How to calculate time difference of two columns with a lag

I am currently facing a dataset of taxi trips by a driver in NYC. I got the driver ID as well as the pickup date and time and dropoff date and time for every trip. Now I want to calculate the waiting time between the dropoff time of the last trip…
Maximilian
  • 89
  • 1
  • 7
-1
votes
1 answer

compare columns dynamically in data.table in R

I have a data.table, which has multiple date columns. The are K date columns, whereby K changes. I have calculated the time difference between the columns: K <- numberOfYears dateCols = c("fromdatenext", paste0("fromdate" , 1:K)) # create formulas…
Nneka
  • 1,764
  • 2
  • 15
  • 39
-1
votes
2 answers

using difftime in R from one column

Hello can you help me with difference in (hours) in R from one column. I use only basic package R. I would like to create new column with hours so the column look like hours<-c(0,24,23,21,31,26,28) time<-c('10. 4. 2018 10:16:11', '11. 4. 2018…
dado
  • 79
  • 5
-1
votes
2 answers

NA difference in as.difftime R

It might seem as if it is duplicate of Find time difference in days with R but I guess it is not. The problem is simple. I have two time stamps (format='%H:%M:%S'): times <- c('02:51:43', '02:45:52') and I want to calculate the time difference,…
storaged
  • 1,837
  • 20
  • 34
-1
votes
1 answer

Using 'difftime' data in a ggplot2 boxplot in R

I created a difftime object to determine the amount of hours it takes to report a crime that has occurred. Also, in the same dataset I have a variable which indicates whether the crime occurred on a weekday or in the weekend. Now I'd like to create…
Frederique
  • 69
  • 1
  • 7
-1
votes
1 answer

c++11 difftime() calculating leap year incorrectly?

I make a simple program to calculate the number of day between two days: #include #include #include #include using namespace std; int main(){ struct tm t1 = {0,0,0,28,2,104}; struct tm t2 =…
Chris Lee
  • 1
  • 2
-1
votes
2 answers

Calculating differences of dates in hours between rows of a dataframe

I have the following dataframe (ts1): D1 Diff 1 20/11/2014 16:00 0.00 2 20/11/2014 17:00 0.01 3 20/11/2014 19:00 0.03 I would like to add a new column to ts1 that will be the difference in hours between successive rows D1 (dates) in…
Avi
  • 2,247
  • 4
  • 30
  • 52
-2
votes
2 answers

Subsetting rows based on dates and criteria across two data frames

I have one data frame outlining pollution levels continuously measured from two sites. Dates <- as.data.frame(seq(as.Date("2015/01/01"), as.Date("2017/01/01"),"day")) Pollution_Site.A <- as.data.frame(c(seq(from = 1, to = 366, by = 1), …
James White
  • 705
  • 2
  • 7
  • 20
-2
votes
1 answer

How can I calculate the difference between these two dates using R?

I have a data set which containing 2 columns with dates with the following formats: "2027-02-20 00:00:00 CET" and "2014-12-31 CET" how can I calculate the difference between these two dates? Or, how can I apply difftime ? Here is a useful…
maniA
  • 1,437
  • 2
  • 21
  • 42
-2
votes
1 answer

Get Minute difference from two SQL columns

I have two columns in a table: 1st column only stores hhmm (Ex. 2350 aka 11:50pm) in varchar(257) format. 2nd column is the timestamp. How do I get the minute difference between the two? Here's the example of two columns. When in Management Studio,…
NonProgrammer
  • 1,337
  • 2
  • 23
  • 53
1 2 3
12
13