Skip to contents

Coerces Vector to a Given Time Class

Usage

utils_coerce_time_class(x = NULL, to = "POSIXct")

Arguments

x

(required, vector of class Date or POSIXct) time vector to convert. Default: NULL

to

(required, class name) class to coerce x to. Either "Date", "POSIXct", "integer" or "numeric". Default: "POSIXct"

Value

time vector

Examples

x <- utils_coerce_time_class(
  x = c("2024-01-01", "2024-02-01"),
  to = "Date"
)

x
#> [1] "2024-01-01" "2024-02-01"
class(x)
#> [1] "Date"

x <- utils_coerce_time_class(
  x = c("2024-01-01", "2024-02-01"),
  to = "POSIXct"
)

x
#> [1] "2024-01-01 UTC" "2024-02-01 UTC"
class(x)
#> [1] "POSIXct" "POSIXt" 

x <- utils_coerce_time_class(
  x = c("2024-01-01", "2024-02-01"),
  to = "numeric"
)

x
#> [1] 19723 19754
class(x)
#> [1] "numeric"