houses date variable ‘d’ as a character string
d <- as.Date.character('05/08/2020', '%m/%d/%y')
checks the data type printing variable ‘d’
print(d)
## [1] "2020-05-08"
loads the lubridate package
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
uses lubriate functions to extract information from ‘d’ into specified variables
d_year <- year(d)
d_month <- month(d)
d_week <- week(d)
d_day <- wday(d)
adds 25 days to the original date ‘d’ and stores it as variable ‘d_25’
d_25 <- d + 25
finds the number of days between ‘d_25’ and ‘d’
difftime(d_25,d)
## Time difference of 25 days