posixct - Calculate time difference between two events (given date and time) in R -
I am currently struggling with the initial issue of calculating the difference of time between the two incidents.
I want to take a column that includes the date and time (both values in a column) and same with ID (A or B) of the value of the previous / next line Together, want to calculate a time difference. ID = C ("A", "A", "B", "B") Time = C ("08.09.2014 10:34", "12.09")
.2014 09 : 33 "," 13.08.2014 15:52 "," 11.09.2014 02:30 ") D = Data. Frame (id, time) My desired output is time in the format : Minute
time difference = c ("94: 59", "9 4:59", "682: 38", "682: 38") format day: hours: minute or anything else will work, as long as it can be conveniently implemented I am flexible about the format of the output, the only one above is the idea above Cross my mind
For each single ID, I always have two rows (in Example 2xA and 2xB) I do not have a smart idea to avoid the repayment of the difference.
I have tried some examples before, which I found on StakeVareflow. Most of them used the POSIXt and striptime . Not manage to implement on my data set
dplyr
Library (DEPUTOR) D% & gt;% Mute (time = as.paceXct (time, format = "% d.% M% Y% H:% M"))%)% & gt;% )% & Gt; % Mutate (diff = paste0 (gsub ("[.]. *", "", Diff (time) * 24), ":", round (as.numeric (gsub (". *. [.]]," " , Difference (time) * 24)) * 60) # Source: Local data frame [4 x 3] # Groups: ID # # ID time difference # 1A 2014-09-08 10:34:00 94: 59 # 2A 2014-09-12 09:33:00 94:59 # 3b 2014-08-13 15:52:00 682: 38 # 4b 2014-09-11 02:30:00 682: 38
Comments
Post a Comment