Below are the solutions to these exercises on dates and times – Simple lubridate Exercises.
#################### # # # Exercise 1 # # # #################### start_date<- dmy("23012017") start_date
## [1] "2017-01-23"
#################### # # # Exercise 2 # # # #################### today()
## [1] "2016-08-14"
#################### # # # Exercise 3 # # # #################### year(start_date)
## [1] 2017
#################### # # # Exercise 4 # # # #################### month(start_date)
## [1] 1
#################### # # # Exercise 5 # # # #################### day(start_date)
## [1] 23
#################### # # # Exercise 6 # # # #################### month(start_date) <- 2 #################### # # # Exercise 7 # # # #################### start_date + days(6)
## [1] "2017-03-01"
#################### # # # Exercise 8 # # # #################### start_date - months(3)
## [1] "2016-11-23"
#################### # # # Exercise 9 # # # #################### concatenated_dates <- dmy(c("31.12.2015", "01.01.2016", "15.02.2016")) concatenated_dates
## [1] "2015-12-31" "2016-01-01" "2016-02-15"
#################### # # # Exercise 10 # # # #################### start_date + c(1:10) * days(1)
## [1] "2017-02-24" "2017-02-25" "2017-02-26" "2017-02-27" "2017-02-28" ## [6] "2017-03-01" "2017-03-02" "2017-03-03" "2017-03-04" "2017-03-05"
My solution for question #10:
start_date + days(c(1:10))
or
start_date+days(1:10)