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
1
vote
1 answer

How do you calculate means for time differences for groups in R?

I am trying to calculate the mean time for national sailing teams in a competition. I want to group the teams together by country to calculate the mean sailing time for USA and Japan. Here's my code, which uses the dplyr function's group_by. Here's…
TDog
  • 165
  • 1
  • 2
  • 9
1
vote
1 answer

diff time r studio is not giving the outcome properly

Im trying to calculate the difftime in minutes between two columns and the results seems to be not right. BLOCK_DATE_TIME.x a1_0 diff 2019-04-26 19:07:00 2019-04-27 09:00:00 773 2019-08-27 08:30:00 2019-08-27 09:00:00 -30 the code to…
1
vote
2 answers

Is there a simple way to calculate minutes between two date_times, excluding a specific interval?

start End minutes 2019-01-11 14:36:00 2019-01-13 16:27:00 2991 What I want is to calculate minutes excluding the interval between 00:00 and 06:00.
1
vote
1 answer

difftime is returning a wrong number

#include #include using namespace std; int main() { double seconds; struct tm birth = {0}; //10-28-1955 birth.tm_year = 55; birth.tm_mon = 9; birth.tm_mday = 28; birth.tm_sec = 0; struct tm…
Ron
  • 13
  • 3
1
vote
1 answer

Why does `difftime` carry label attribute from other variable in R?

In my example below I create a label for a date variable using Hmisc (can be the labelled package doesn't matter). In the second dataset I use difftime to take the difference between two dates. When you run attributes on the new column the label…
Mike
  • 3,797
  • 1
  • 11
  • 30
1
vote
2 answers

How to calculate time intervals of dates within groups in R?

I have data of 2 million transactions that include userID, invoice nr, invoice date and items purchased. I would like to find out what is the average time interval in between purchases (by customer). sample.data <- data.frame(userID = c("ID1",…
1
vote
1 answer

Shiny dynamical modalDialog render* difftime

In an attempt to solve this question R Shiny: display elapsed time while function is running, I tried several things, and I have questions about the modal dialog. Here is a MWE library(shiny) ui <- fluidPage( sidebarLayout( sidebarPanel( …
Antoine
  • 269
  • 1
  • 10
1
vote
1 answer

Group_by a unique value and find duration, while satisfying multiple conditions in R (dplyr)

I have a dataset, sample: Ultimately I would like to be able to group the data into 'chunks' where the Subject column contains a unique value and where the Folder column shows 'Outdata', and where the Message column is blank. I am trying to find the…
Lynn
  • 4,292
  • 5
  • 21
  • 44
1
vote
1 answer

Group and rename based on two conditions in R (dplyr)

I have a dataset, df: Ultimately I would like to be able to group the data into 'chunks' where the Folder column contains the string 'Out', making sure to consider the DATE and the empty Message values that it is associated with. Is there a way to…
Lynn
  • 4,292
  • 5
  • 21
  • 44
1
vote
1 answer

Dplyr time difference for each row in a group

I am trying to calculate my email durations. I have emails grouped by ID. In this example, I have already grouped my emails by group A. I wish to calculate my email read time duration for group A. The code I am currently using, calculates its last…
Lynn
  • 4,292
  • 5
  • 21
  • 44
1
vote
1 answer

How to calculate occupancy rate per hour?

I'm trying to calculate occupancy rate per hour in R. To do that I need the minutes of one meeting (difference in start and end time) and divide it by 60 minutes times 100%. I have trouble calculating this when the endtime is in a different hour…
user12220606
1
vote
2 answers

How to read in timestamps of format %Y-%m-%d %H:%M:%OS3 (and do math with it)?

I have a .txt file (without any clear column delimiter) which, in each line, contains a timestamp of the format %H-%m-%d %H:%M:%OS3 (e.g. "2019-09-26 07:29:22,778") and an event character string. I would like to read-in the data and make a table…
VGF
  • 55
  • 8
1
vote
2 answers

how to calculate MTD in R for a different month

The task is to find number of days in MTD for two months, the month that had highest inflow numbers (July) in my case and the present month. Because I plan to run the statement as a script everyday, I don't want to hardcode anything. The dataframe…
Karthik S
  • 11,348
  • 2
  • 11
  • 25
1
vote
2 answers

Calculate seconds between 2 timestamps in R excluding weekends

If I have a dataframe with 2 columns which are YMD HMS, how do I calculate the difference in seconds between the two excluding weekends? col 2 - col 1 = time in seconds; need to exclude the weekend seconds Dates1 <- as.POSIXct("2011-01-30 12:00:00")…
user_1771
  • 47
  • 7
1
vote
0 answers

Calculating all possible "time difference" combinations in R

I'm using camera trapping data which contains two columns: "datetime" of when the photo was taken "species" species that appears in the photo I want to calculate time difference between all possible pairs of species in R. I have used difftime and…
Miriam
  • 11
  • 3