R/utils.R
combine_date_time_cols.Rd
Combine date and time columns into a single DateTime column
combine_date_time_cols(.data, tz = NULL)
(data.frame) A data frame or data frame extension (e.g. a tibble)
(character) a time zone name (default: time zone of the POSIXt object x)
(data.frame) An object of the same type as .data
df <- data.frame(
date_a = as.Date(c("2020-01-01", "2020-01-02")),
date_b = as.POSIXct(c("2020-02-01", "2020-02-02")),
time_a = as.POSIXct(c("1900-01-01 01:01:01", "1900-01-01 02:02:02")),
time_b = as.POSIXct(c("1900-01-01 01:01:01", "1900-01-01 02:02:02"))
)
combine_date_time_cols(df)
#> # A tibble: 2 × 2
#> DateTime_a DateTime_b
#> <dttm> <dttm>
#> 1 2020-01-01 01:01:01 2020-02-01 01:01:01
#> 2 2020-01-02 02:02:02 2020-02-02 02:02:02