Below are the solutions to these exercises on Lubridate topic.
library(lubridate) #################### # # # Exercise 1 # # # #################### dseconds(160)
## [1] "160s (~2.67 minutes)"
#################### # # # Exercise 2 # # # #################### dminutes(160) / 60
## [1] "160s (~2.67 minutes)"
#################### # # # Exercise 3 # # # #################### ddays(1) - dminutes(160)
## [1] "76800s (~21.33 hours)"
#################### # # # Exercise 4 # # # #################### duration(day = 12, hour = 5, minute = 10)
## [1] "1055400s (~12.22 days)"
#################### # # # Exercise 5 # # # #################### weeks(2) * c(0:10)
## [1] "0S" "14d 0H 0M 0S" "28d 0H 0M 0S" "42d 0H 0M 0S" ## [5] "56d 0H 0M 0S" "70d 0H 0M 0S" "84d 0H 0M 0S" "98d 0H 0M 0S" ## [9] "112d 0H 0M 0S" "126d 0H 0M 0S" "140d 0H 0M 0S"
#################### # # # Exercise 6 # # # #################### round_date(ymd('2016-10-16'),"month")
## [1] "2016-10-01"
#################### # # # Exercise 7 # # # #################### floor_date(ymd('2016-10-16'),"month")
## [1] "2016-10-01"
#################### # # # Exercise 8 # # # #################### ceiling_date(ymd('2016-10-16'),"month")
## [1] "2016-11-01"
#################### # # # Exercise 9-10 # # # #################### date1 <- ymd('2016-11-01') wday(date1,label = TRUE, abbr = FALSE)
## [1] Tuesday ## 7 Levels: Sunday < Monday < Tuesday < Wednesday < Thursday < ... < Saturday
date2 <- date1 + days(2) wday(date2,label = TRUE, abbr = FALSE)
## [1] Thursday ## 7 Levels: Sunday < Monday < Tuesday < Wednesday < Thursday < ... < Saturday
date2 + weeks(3)
## [1] "2016-11-24"



Leave a Reply