Given that this is your data (here admission2 and time_lorazepam2 are already in datetime format):
library(dplyr)
library(tibble)
dat <- tribble(~ admission2, ~ time_lorazepam2, ~admission_to_lorazepam,
"2015-08-05 01:52:00", "2015-08-05 02:57:00", 65,
"2015-08-17 02:00:00", "2015-08-17 01:26:00", -34,
"2016-02-25 18:59:00", "2016-02-25 20:15:00", 76
) %>% mutate(across(c(admission2, time_lorazepam2), as.POSIXct))
dat
#> # A tibble: 3 x 3
#> admission2 time_lorazepam2 admission_to_lorazepam
#> <dttm> <dttm> <dbl>
#> 1 2015-08-05 01:52:00 2015-08-05 02:57:00 65
#> 2 2015-08-17 02:00:00 2015-08-17 01:26:00 -34
#> 3 2016-02-25 18:59:00 2016-02-25 20:15:00 76
I think you want to do:
dat %>% mutate(admission2 = if_else(admission2 == as.POSIXct("2015-08-17 02:00:00"),
as.POSIXct("2015-08-17 01:26:00"),
admission2))
#> # A tibble: 3 x 3
#> admission2 time_lorazepam2 admission_to_lorazepam
#> <dttm> <dttm> <dbl>
#> 1 2015-08-05 01:52:00 2015-08-05 02:57:00 65
#> 2 2015-08-17 01:26:00 2015-08-17 01:26:00 -34
#> 3 2016-02-25 18:59:00 2016-02-25 20:15:00 76
To be save, you could add a condition admission_to_lorazepam < 0 , to really only change the line where admission is "2015-08-17 02:00:00" and admission_to_lorazepam is a negative number:
dat %>% mutate(admission2 = if_else(admission2 == as.POSIXct("2015-08-17 02:00:00") & admission_to_lorazepam < 0,
as.POSIXct("2015-08-17 01:26:00"),
admission2))
#> # A tibble: 3 x 3
#> admission2 time_lorazepam2 admission_to_lorazepam
#> <dttm> <dttm> <dbl>
#> 1 2015-08-05 01:52:00 2015-08-05 02:57:00 65
#> 2 2015-08-17 01:26:00 2015-08-17 01:26:00 -34
#> 3 2016-02-25 18:59:00 2016-02-25 20:15:00 76
Or you could just change all dates with a negative admission_to_lorazepam:
dat %>% mutate(admission2 = if_else(admission_to_lorazepam < 0,
time_lorazepam2 ,
admission2))
#> # A tibble: 3 x 3
#> admission2 time_lorazepam2 admission_to_lorazepam
#> <dttm> <dttm> <dbl>
#> 1 2015-08-05 01:52:00 2015-08-05 02:57:00 65
#> 2 2015-08-17 01:26:00 2015-08-17 01:26:00 -34
#> 3 2016-02-25 18:59:00 2016-02-25 20:15:00 76
Created on 2022-07-29 by the reprex package (v2.0.1)