#' Fix a character field to date
#'
#' This function will return a dataframe with all
#' @param df dataframe you want add information to
#' @param format formt that date is currently in so we can parse it
#' @param date_search character string to search for within the names of each column; Any that match will be changed to a date format
#' @export
#' @examples
#' fix_dates(myydataframe)
fix_dates<-function(df, format="%Y-%m-%d %H:%M:%S", date_search="date"){
if (!requireNamespace("lubridate", quietly = TRUE)) {
stop("lubridate needed for this function to work. Please install it.",
call. = FALSE)
}
library(lubridate)
df[,grep(date_search,
colnames(df))] <- lapply(df[,grep(date_search,
colnames(df))],
fast_strptime,
format = format,
lt=F)
return(df)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.