Справочная информация:
У меня есть набор данных, df, где я хотел бы следовать определенному шаблону относительно временных отметок. Я хотел бы сначала
1. Identify the 'Connect' value timestamp
2. Check the action that follows, and check to see if the next action
is an 'Ended' or 'Attempt' with a less than or equal to 60 second gap
3. If this <= gap of 60 second is present, I wish for the code to Skip these timestamps
and keep iterating until it comes to the next 'Ended' value, and to record this value.
Шаблон вывода всегда должен следовать за 'Connect' и 'Ended'
We start with:
Connect 4/6/2020 1:11:41 PM
Then look to the next line:
Ended 4/6/2020 1:14:20 PM
Now look to the line that follows:
Attempt 4/6/2020 1:15:20 PM
These two timestamps are less than or equal to 60 seconds, so we keep going
until we come across an Ended value where these conditions do not apply.
So the Ended value of
Ended 4/6/2020 2:05:18 PM gets recorded.
Action Time
Connect 4/6/2020 1:11:41 PM
Ended 4/6/2020 1:14:20 PM
Attempt 4/6/2020 1:15:20 PM
Connect 4/6/2020 1:15:21 PM
Ended 4/6/2020 2:05:18 PM
Connect 3/31/2020 11:00:08 AM
Ended 3/31/2020 11:14:54 AM
Ended 3/31/2020 4:17:43 PM
Как мы увидим ниже, эти строки были удалены начиная с 1: 14:20 PM и 13:15:20 PM равны или меньше 60 se c друг от друга, и 31.03.2020 16:17:43 PM не является следующим непосредственным значением 'Ended', с которым мы сталкиваемся.
Ended 4/6/2020 1:14:20 PM
Attempt 4/6/2020 1:15:20 PM
Connect 4/6/2020 1:15:21 PM
Ended 3/31/2020 4:17:43 PM
Требуемый выход:
Action Time
Connect 4/6/2020 1:11:41 PM
Ended 4/6/2020 2:05:18 PM
Connect 3/31/2020 11:00:08 AM
Ended 3/31/2020 11:14:54 AM
Выходной шаблон всегда должен следовать за 'Connect' и 'Ended'
Dput:
structure(list(Action = structure(c(2L, 3L, 1L, 2L, 3L, 2L, 3L,
3L), .Label = c("Attempt", "Connect", "Ended"), class = "factor"),
Time = structure(c(4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L), .Label = c("3/31/2020 11:00:08 AM",
"3/31/2020 11:14:54 AM", "3/31/2020 4:17:43 PM", "4/6/2020 1:11:41 PM",
"4/6/2020 1:14:20 PM", "4/6/2020 1:15:20 PM", "4/6/2020 1:15:21 PM",
"4/6/2020 2:05:18 PM"), class = "factor")), class = "data.frame", row.names = c(NA,
-8L))
Это то, что я пробовал:
Я думаю, что я должен использовать al oop, но не совсем уверен, как построить это. Любая помощь приветствуется.
library(lubridate)
if (value <= 60) {
print("")
} else {
Expr2
}