Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Answers to the exercises are available here.
If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.
Exercise 1
create a vector 22_mar_2018 as a vector which is like
mar_22_2018 <- c("mar-22-2018","2018/03/22", "2018-03-22","22 mar 2018")
parse it with anytime function from anytime package
Exercise 2
anydate/anytime bydefault converts to the local time zone,use asUTC to TRUE to set the timezone as UTC to see the current time in UTC and date as well
Exercise 3
R has builtin datetime object ,convert mar 22 2018 12:30:00 to R datetime .
Exercise 4
you can see the timezone of your system using sys.timezone() method , now do the prev exercise again but set the time zone to “Europe/London”
Exercise 5
install and load the library lubridate into your R session.
create a string “2018-mar-22” ,convert it to R date object (ISO 8601 ) using ymd function from lubridate . ymd parses a date like string into R’s date format if
- Work with different packages that help shape dates and times,
- learn about the lubridate package for quick and easy dates and times,
- and much more
Exercise 6
use dmy function to convert a date string “22-mar-2018” where string is of the form of dd-mon-yyyy or similar to R’s date format .
Exercise 7
use mdy function to convert string ” mar-22-2018″ to R’s date format
Exercise 8
There are other similar functions like dym,mdy etc in lubridate , play with them to get a feel of the different date parsing functions in lubridate.
Related exercise sets:
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.