Одним из подходов будет использование dplyr
и lubridate
с вашим if_else
подходом.
library(dplyr)
library(lubridate)
data %>%
mutate(Date = mdy(Date),Time = hms(Time)) %>%
mutate(UpdatedDate = if_else(Time < hms("07:00:00"), Date - days(1), Date))
# Country Date Time UpdatedDate
#1 Alamance 2015-08-11 17H 38M 0S 2015-08-11
#2 Alamance 2012-11-08 15H 52M 0S 2012-11-08
#3 Alamance 2017-11-18 20H 59M 0S 2017-11-18
#4 Alamance 2005-02-18 15H 3M 0S 2005-02-18
#5 Alamance 2008-03-23 21H 3M 0S 2008-03-23
#6 Alamance 2008-08-02 0S 2008-08-01
#7 Alamance 2007-12-21 3H 54M 0S 2007-12-20
#8 Alamance 2010-03-28 36M 0S 2010-03-27
#9 Alamance 2007-06-30 22H 17M 0S 2007-06-30
Данные
data <- data.frame(Country = "Alamance",
Date = c("8/11/2015","11/8/2012","11/18/2017","2/18/2005","3/23/2008","8/2/2008","12/21/2007","3/28/2010","6/30/2007"),
Time = c("17:38:00","15:52:00","20:59:00","15:03:00","21:03:00","0:00:00","3:54:00","0:36:00","22:17:00"))