knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(relper)
dttm_
functions help in the manipulation of date and datetime variables.
The goal of dttm_diff
is to compute the difference between two dates.
date1 <- lubridate::dmy("01/05/1998") date2 <- lubridate::dmy("21/11/2018") dttm_diff(date1 = date1,date2 = date2,unit = "days")
So the time difference between 21/11/2018 and 01/05/1998 is 7,509 days.
If you need to add a constant to your difference, use the add
argument.
dttm_diff(date1 = date1,date2 = date2,unit = "days",add = 1)
The goal of dttm_vars
is to compute variables derived from date, such as year, month, day, etc.
dt <- seq(as.Date("1910/1/1"), as.Date("1911/1/1"), "days") df_dt <- data.frame(dt = dt) dttm_vars(df_dt,dt) %>% dplyr::glimpse()
The new variables respective to the date are:
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.