Below are the solutions to these exercises on date and time
############### # # # Exercise 1 # # # ############### library(anytime)
## Warning: package 'anytime' was built under R version 3.4.4
library(lubridate) mar_22_2018 <- c("mar-22-2018","2018/03/22", "2018-03-22","22 mar 2018") anytime(mar_22_2018)
## [1] "2018-03-22 PDT" "2018-03-22 PDT" "2018-03-22 PDT" "2018-03-22 PDT"
############### # # # Exercise 2 # # # ############### anytime(mar_22_2018,asUTC = T)
## [1] "2018-03-21 17:00:00 PDT" "2018-03-21 17:00:00 PDT" ## [3] "2018-03-21 17:00:00 PDT" "2018-03-21 17:00:00 PDT"
############### # # # Exercise 3 # # # ############### as.POSIXct("2018-03-22 12:30:00")
## [1] "2018-03-22 12:30:00 PDT"
############### # # # Exercise 4 # # # ############### as.POSIXct("2018-03-22 12:30:00","Europe/London")
## [1] "2018-03-22 12:30:00 GMT"
############### # # # Exercise 5 # # # ############### require(lubridate) ymd("2018-mar-22")
## [1] "2018-03-22"
############### # # # Exercise 6 # # # ############### dmy("22-mar-2018")
## [1] "2018-03-22"
############### # # # Exercise 7 # # # ############### mdy("mar-22-2018")
## [1] "2018-03-22"
############### # # # Exercise 8 # # # ############### dym("22/2018/03")
## [1] "2018-03-22"
ymd("2018-03-22")
## [1] "2018-03-22"
Leave a Reply