[This article was first published on R-exercises, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The `as.date()` function creates objects of the class “`Date`“, via input of character representations of dates.

Answers to the exercises are available here.

Exercise 1

The format of `as.Date(x, ...)` accepts character dates in the format, “YYYY-MM-DD”.

For the first exercise, use the `c()` function, and `as.date()`, to convert “`2010-05-01`” and “`2004-03-15`” to class “`date`” objects. Set a variable called, “`Exer1Dates`“.

Exercise 2

With `as.Date(x, format, ...)`, the structure of the character dates are specified by the “`format =`” parameter.

For this exercise, use `as.date(x, format, ...)` to convert “`07/19/98`” to a date object within the variable, “`Exer2Date`“.

Exercise 3

The parameter, “`origin =`” converts dates from Windows Excel, (where 1900 is mistakenly designated as a leap year), to R format, via “`origin = "1899-12-30"`“.

Therefore, convert the Windows Excel dates of “`31539`“, “`31540`“, and
`31541`” to date objects, without setting a variable.

Exercise 4

Convert “`02/07/10`“, “`02/23/10`“, “`02/08/10`“, “`02/14/10`“, and
`02/10/10`“, into date objects within the variable, “`Exer4Dates`“.

Exercise 5

Find the mean of the date object variable “`Exer4Dates`“.

Exercise 6

Find the max date in “`Exer4Dates`“.

Exercise 7

Convert “`10/25/2005`“, and “`06/08/1971`” into a date object.

Exercise 8

Convert “`Exer4Dates`” to character data. Set a variable called, “`chrDates`“.

Exercise 9

Use the “`format()`“, and “`Sys.Date()`“, functions to print today’s date, with a format of “`%B %d %Y`“.

Exercise 10

Use “`format()`” and “`Sys.time()`” to print today’s date, with the time zone set to “`Hawaii Standard Time`“.

Image by Maklay62 (Pixabay post) [CC0 Public Domain ], via Pixabay.

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 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.

# 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)