Parsing Dates and Time – Part 2: Exercises

April 11, 2018
By

(This article was first published on R-exercises, and kindly contributed to R-bloggers)

In the exercises below, we will continue working with lubridate and examine more features of the library.
Answers to these exercises are available here.
Please check the previous exercise 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
Here is a string, which looks like:
dt <- "Apr, 11th 2018 17:00" .
Convert it to R’s date-time format.

Exercise 2

Here is another representation of dt:
dt <- "2018/04/11 17:00" .
Convert it to R’s date-time format.

Exercise 3

Suppose dt is in this format:

dt <- "11.4.2018 17"
Convert it to R’s date-time format.

Exercise 4

Lubridate allows you to parse dates and times in a convoluted format into R’s date-time format.
dt <- "Wed apr 11th 2018 at 7pm"

Parse it properly using the lubridate’s function.

Exercise 5

Suppose I have to parse the 110th day of 2018; how do I achieve that?

Exercise 6

Now, suppose you have two strings: “1 2018”, which represents the first quarter of 2018 and “3 2018”, which represents the 3rd quarter of 2018. Using lubridate’s functions, parse it properly.

Exercise 7

Suppose you have to parse the 10th week of 2018; please parse it with lubridate.

To leave a comment for the author, please follow the link and comment on their blog: R-exercises.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)