difftime

Calculating differences of dates in hours between rows of a dataframe

十年热恋 提交于 2019-12-12 06:56:43
问题 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 hours. The new ts1 should be: D1 Diff N 1 20/11/2014 16:00 0.00 2 20/11/2014 17:00 0.01 1 3 20/11/2014 19:00 0.03 2 For calculating the difference in hours independently I use: library(lubridate) difftime(dmy_hm("29/12/2014 11:00"), dmy_hm("29/12/2014 9:00"),

Average number of seconds between two time observations

↘锁芯ラ 提交于 2019-12-10 22:31:10
问题 I have a irregular time index from an xts object. I need to find the average number of seconds between two time observations. This is the my sample data: dput(tt) structure(c(1371.25, NA, 1373.95, NA, NA, 1373, NA, 1373.95, 1373.9, NA, NA, 1374, 1374.15, NA, 1374, 1373.85, 1372.55, 1374.05, 1374.15, 1374.75, NA, NA, 1375.9, 1374.05, NA, NA, NA, NA, NA, NA, NA, 1375, NA, NA, NA, NA, NA, 1376.35, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1376.25, NA, 1378, 1376.5, NA, NA, NA, 1378, 1378, NA, NA,

Get the time difference from time varaibles stored as character

岁酱吖の 提交于 2019-12-10 18:23:45
问题 I have two character variables in my dataframe start_time and stop_time : start_time stop_time <chr> <chr> 1 19:5:00 19:11:00 2 20:33:37 20:34:39 3 20:23:00 20:23:38 4 20:12:00 20:13:00 5 20:00:39 20:00:39 I would like to calculate the difference between start_time and stop_time in terms of minutes with dplyr. My problem is that the two variables are expressed as a character. expected output: diff_time <dbl> 1 6 2 1.2 3 0.38 4 1 5 0.39 回答1: library(dplyr) library(lubridate) df1 %>% mutate

difftime() adds decimal numbers

百般思念 提交于 2019-12-09 01:47:36
问题 I am trying to get the number of days from a specific date using difftime(). If I use the November date (10.11.14) it works fine, if I use the September date (10.09.14) it adds .0417 to the date. Any idea how I can solve this? head(dummydat) reihe nummer bluh_datum 1 1 1 07.03.15 2 1 2 11.03.15 3 1 3 09.03.15 4 1 4 <NA> 5 1 5 <NA> 6 1 6 07.03.15 dummydat <- cbind(dummydat,"days"=as.numeric(difftime(strptime(dummydat$bluh_datum, format="%d.%m.%y"),strptime("10.11.14", format="%d.%m.%y"), units

Calculating conditional cumulative time

孤人 提交于 2019-12-08 05:22:34
问题 Following the pointers from this question. I'd like to calculate the cumulative time for all the Cat s, by considering their respective last toggle status. EDIT: I'd also want to check if the FIRST Toggle status of a Cat is Off and if it is so, for that specific cat , the time from midnight 00:00:00 till this first FIRST Off time should be added to its total conditional cumulative ontime. Sample data: Time Cat Toggle 1 05:12:09 36 On 2 05:12:12 26R Off # First Toggle of this Cat happens to be

Calculate time difference (difftime) between columns of different rows

梦想的初衷 提交于 2019-12-06 06:47:42
I have data on 'Start' and 'End' time for different jobs, grouped by 'owner': Data <- data.frame( job = c(1, 2, 3, 4, 5), owner = c("name1", "name2", "name1", "name1", "name2"), Start = as.POSIXct(c("2015-01-01 15:00:00", "2015-01-01 15:01:00", "2015-01-01 15:13:00", "2015-01-01 15:20:00", "2015-01-01 15:39:02"), format="%Y-%m-%d %H:%M:%S"), End = as.POSIXct(c("2015-01-01 15:11:11", "2015-01-01 15:17:21", "2015-01-01 15:17:00", "2015-01-01 15:31:21", "2015-01-01 15:40:11"), format="%Y-%m-%d %H:%M:%S") ) For each owner, I want to calculate the idle time between the jobs for each owner, i.e. the

How to calculate time differences in C++ with time_t before the epoch?

无人久伴 提交于 2019-12-06 04:01:14
问题 What I would like to do with my simple program is to calculate a difference in seconds between two dates. time_t referenceDate; time_t dateNow = time(0); struct tm referenceDateComponent = {0}; referenceDateComponent.tm_hour = 0; referenceDateComponent.tm_min = 0; referenceDateComponent.tm_sec = 0; referenceDateComponent.tm_year = 89; referenceDateComponent.tm_mon = 11; referenceDateComponent.tm_mday = 31; referenceDate = mktime(&referenceDateComponent); long seconds = difftime(dateNow,

difftime() adds decimal numbers

删除回忆录丶 提交于 2019-12-01 01:22:20
I am trying to get the number of days from a specific date using difftime(). If I use the November date (10.11.14) it works fine, if I use the September date (10.09.14) it adds .0417 to the date. Any idea how I can solve this? head(dummydat) reihe nummer bluh_datum 1 1 1 07.03.15 2 1 2 11.03.15 3 1 3 09.03.15 4 1 4 <NA> 5 1 5 <NA> 6 1 6 07.03.15 dummydat <- cbind(dummydat,"days"=as.numeric(difftime(strptime(dummydat$bluh_datum, format="%d.%m.%y"),strptime("10.11.14", format="%d.%m.%y"), units="days"))) > head(dummydat) reihe nummer bluh_datum days 1 1 1 07.03.15 117 2 1 2 11.03.15 121 3 1 3 09