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

Months difference function inconsistency

I have two vectors of dates. I need to find the difference in months between the two. In a subset of the two vectors I have no problem. However, as soon as I include the whole vector calculation stop making sense. For example the difference between…
MCS
  • 1,071
  • 9
  • 23
0
votes
1 answer

Issue with hms difftime type in R

I have two dataframes that are very similar that I am trying to rbind together, but am running into an issue. I used dput() to grab 3 columns (one of which is problematic) and 10 rows from each dataframe. str1 = structure(list(period_type =…
Canovice
  • 9,012
  • 22
  • 93
  • 211
0
votes
1 answer

Create 24 columns and a dummy if timespan overlaps with hour

I have a "start" and "end" timestamp. df <- structure(list(Vagt_Start = structure(c(1535412600, 1531006200, 1518823800, 1535671800, 1531092600, 1527550200, 1535499000, 1530919800, …
xhr489
  • 1,957
  • 13
  • 39
0
votes
1 answer

difftime with lag/lead based on condition from other column (and tidy data structure)

I have taken a function from this post to create a random time efficiently generate a random sample of times and dates between two dates. Here is my data set: latemail <- function(N, st="2012/01/01", et="2012/12/31") { st <-…
xhr489
  • 1,957
  • 13
  • 39
0
votes
1 answer

Calculate changing date for a Donchian Channel technical indicator

I am trying to create an indicator that has a dynamic n that changes each day. Basically I am making a strategy that enters a trade when a stocks price reaches its all time highest price. The best way I can think to do this is by using a Donchian…
0
votes
1 answer

How to convert colon notation duration time if we have more than 60 minutes

I am stuck with something simple: I have vector of minutes and seconds like, e.g., myvec=c("10:56","2:32","0:00","0:00","62:59","60:40","46:23"). Here the number before the : notes the minutes and after the colon we have the seconds. I tried…
5th
  • 2,097
  • 3
  • 22
  • 41
0
votes
1 answer

calculate difference between 2 dates and print the between dates

st_day<-c(1,5,10) endday<-c(4,9,15) d<-c(1,2,3) data<-cbind(st_day,endday,d) days1<-c(1:15) dose1<-rep(c(1,2,3),each=5) result <- cbind(days1,dose1) Hello I have 2 coulmns with starts and end dates and corresponding dose with was a…
0
votes
1 answer

R - Error in nested ifelse conditioned on character, time and date variables

This questions is basically an extension to my following post R - Conditional operations on time variables and dates The issue I have is due to an error occuring in the extension in form of a nested ifelse statement (e.g. see…
Chellarioo
  • 27
  • 1
  • 6
0
votes
1 answer

difftime in R is not calculating correctly

I am trying to find the difference between two dates in hours, and for the time differences that occur over the span of more than one day I am getting really outrageous and incorrect numbers. Here is an example of the data: Observation …
KKolo
  • 35
  • 1
  • 7
0
votes
2 answers

R Difference in time between rows

I've triangulated information from other SO answers for the below code, but getting stuck with an error message. Searched SO for similar errors and resolutions but haven't been able to figure it out, so help is appreciated. For every group ("id"),…
Bananas
  • 3
  • 5
0
votes
1 answer

Difftime between rows inconsistent

I want to calculate the day-difference between two rows (per ID) with difftime. At the beginning I get the right results but in some lines there are inconsistent values: PatId Date Tage 3l 2015-02-10 NA 3l 2015-03-30 48 3l 2015-06-03 65 ... 5r…
AO_30
  • 39
  • 5
0
votes
1 answer

Finding the days between 2 days using functions in R and condensing the vector

So I need to create a function that take a number of dates, n, and creates a new vector with date ranges, n-1, and the different in number of days between those dates ranges. c("Jan. 20, 2009", "July 20, 1969", "June 28, 1914", "July 14, 1789",…
stevie kay
  • 53
  • 1
  • 6
0
votes
2 answers

difftime in R with date/times spanning midnight

I have a dataset where I am using difftime to calculate the difference between two times in R. For 4 of the records that start in one day and continue past midnight I am getting nonsense answers. …
user41509
  • 978
  • 1
  • 10
  • 31
0
votes
2 answers

Filter eventlogs that are within a time-interval in R using dplyr

I have an event log in the format below. Original format I have created groups by DATE and ID using dplyr,hence a change in either date or ID will be taken as a different group. I want to have only events that are >= 5secs time interval and remove…
Vinds
  • 35
  • 1
  • 8
0
votes
1 answer

R - Difference Dates in new Row

I'm not a pro in R and maybe someone can help me with this function. There is a merged Dataframe (Analyse) with 2 rows (2 different Dates) and I need a new row with the difference between the two dates (in days). I tried it with difftime but the…
AO_30
  • 39
  • 5