У меня есть data.table
, который содержит дату и временные метки для даты начала и окончания. Я знаю, что могу рассчитать разницу во времени, используя функцию difftime
. Но я хочу рассчитать разницу во времени и разделить ее на отдельные часы в каждой строке вместе с копией остальных данных. Например:
Start_time End_time
1: 2017-01-01 00:15:00 2017-01-01 00:23:00
2: 2017-01-01 00:24:00 2017-02-01 00:10:00
3: 2017-01-01 23:38:00 2017-02-01 00:45:00
4: 2017-01-01 14:38:00 2017-01-01 07:43:00
5: 2017-01-01 06:38:00 2017-01-01 00:43:00
я сделал следующее, чтобы извлечь час начала и час окончания
Start_time End_time start_hour end hour
1: 2017-01-01 00:15:00 2017-01-01 00:23:00 0 0
2: 2017-01-01 00:24:00 2017-02-01 00:10:00 0 0
3: 2017-01-01 23:38:00 2017-02-01 00:45:00 23 0
4: 2017-01-01 14:38:00 2017-01-01 07:43:00 14 7
5: 2017-01-01 06:38:00 2017-01-01 00:43:00 6 0
now, i have to find all the temperatures between start_hour and end_hour inclusive and populate my table
i have a weather report which is collected hourly with corresponding temperature,
**DateTime** **Temperature** hour
1 2017-01-01 06:00:00 16 6
2 2017-01-01 05:00:00 16 5
3 2017-01-01 04:00:00 16 4
4 2017-01-01 08:00:00 9 8
5 2017-01-01 03:00:00 5 3
6 2017-01-01 00:00:00 8 0
7 2017-01-01 07:00:00 5 7
i have to get all the temperatures between the starttime and end time (inclusive)
ie. if a ride is for 4 hours on a day, 2017-01-01 00:05:00 till 2017-01-01
04:00:00 i need 4 rows with 4 different temperatures 00:00:00 , 01:00:00, 02:00:00, 03:00:00,04:00:00 .
date should also be considered here ex: 2017-01-01 23:45:00 till 2017-02-01 14:45:00 ,
i need 15 rows for corresponding temperature.
i am struggling with issue and couldnot find a solution,kindly help