Skip to contents

Helpful for when a date object needs to be printed or stored in a SQL database, since SQL databases do not (always) support date-time classes used in R.

Usage

date_cols_to_char(data)

Arguments

data

A data frame.

Value

A data frame with all columns with the class Date or POSIXct converted to character.

Examples

df <- iris
df$dates <- Sys.Date() + sample(1:1000, size = nrow(iris))
converted_df <- date_cols_to_char(df)
# the date variable is now converted, while all other columns are unchanged:
sapply(converted_df, class)
#> Sepal.Length  Sepal.Width Petal.Length  Petal.Width      Species        dates 
#>    "numeric"    "numeric"    "numeric"    "numeric"     "factor"  "character"