#“Introduction To Business Analytics with R”

Create a datetime object d from the character string “05/08/2020”

d <- as.Date(“05/08/2020”, format = “%m/%d/%Y”)

Check the data type of the d object

print(d)

Install the lubridate package

(This assumes that the package pane in RStudio is used to install packages)

install.packages(“lubridate”)

Load the lubridate package

library(lubridate)

Extract year, month number, week number, and weekday number from the object d

d_year <- year(d) d_month <- month(d) d_week <- week(d) d_day <- wday(d)

Display the extracted information

print(d_year) print(d_month) print(d_week) print(d_day)

Create a datetime object d_25, 25 days from now, using the lubridate package

d_25 <- d + days(25) # Display the d_25 object print(d_25)

Calculate the difference between d and d_25 using difftime

diff <- difftime(d_25, d, units = “days”) # Display the difference and check if it’s 25 days print(diff) print(diff == 25)