Skip to contents

These functions can split the "date" and "time" components of POSIXt columns and the "hour", "month", and "day" components of Date columns into multiple columns.

Usage

split_datetimes(data, cols = NULL, class = c("character", "date"))

split_dates(data, cols = NULL)

Arguments

data

input dataframe

cols

set of columns to apply transformation to. If NULL will apply to all POSIXt columns (for split_datetimes()) or Date columns (for split_dates()).

class

For split_datetimes(). The desired output of the separate "date" and "time" columns. "character" leaves the columns as character vectors. "date" will reformat the date as a "Date" and the time as a "POSIXct" object, with a dummy date appended to it. In split_dates(), all returned columns are integers.

Value

a dataframe

See also

Other Messy date(time) functions: messy_datetime_formats(), messy_datetime_tzones()

Author

Jack Davison

Examples

# split datetimes
data <- data.frame(today = Sys.time())
split_datetimes(data)
#>   today_date today_time
#> 1 2024/12/03   23:03:52
# split dates
data <- data.frame(today = Sys.Date())
data
#>        today
#> 1 2024-12-03
split_dates(data)
#>   today_year today_month today_day
#> 1       2024          12         3