<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/as-date-exercises/"></div></div><div><a data-url="http://www.r-bloggers.com/as-date-exercises/" data-counturl="http://www.r-bloggers.com/as-date-exercises/" data-count="horizontal" data-text="As.Date() Exercises" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r-exercises.com/2016/07/14/as-date-exercises/"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a target="_blank" href="http://i0.wp.com/r-exercises.com/wp-content/uploads/2016/07/one-day-left-1420997__180.png"><img alt="one-day-left-1420997__180" class="wp-image-917" src="http://i0.wp.com/r-exercises.com/wp-content/uploads/2016/07/one-day-left-1420997__180.png?resize=173%2C180" data-recalc-dims="1"></a>The <code>as.date()</code> function creates objects of the class “<code>Date</code>“, via input of character representations of dates.</p>
<p>Answers to the exercises are available <a target="_blank" href="http://r-exercises.com/2016/07/14/as-date-solutions/">here</a>.</p>
<p><strong>Exercise 1</strong></p>
<p>The format of <code>as.Date(x, ...)</code> accepts character dates in the format, “YYYY-MM-DD”.</p>
<p>For the first exercise, use the <code>c()</code> function, and <code>as.date()</code>, to convert “<code>2010-05-01</code>” and “<code>2004-03-15</code>” to class “<code>date</code>” objects. Set a variable called, “<code>Exer1Dates</code>“.</p>
<p><strong>Exercise 2</strong></p>
<p>With <code>as.Date(x, format, ...)</code>, the structure of the character dates are specified by the “<code>format =</code>” parameter.</p>
<p>For this exercise, use <code>as.date(x, format, ...)</code> to convert “<code>07/19/98</code>” to a date object within the variable, “<code>Exer2Date</code>“.</p>
<p><strong>Exercise 3</strong></p>
<p>The parameter, “<code>origin =</code>” converts dates from Windows Excel, (where 1900 is mistakenly designated as a leap year), to R format, via “<code>origin = &quot;1899-12-30&quot;</code>“.</p>
<p>Therefore, convert the Windows Excel dates of “<code>31539</code>“, “<code>31540</code>“, and<br>
“<code>31541</code>” to date objects, without setting a variable.</p>
<p><strong>Exercise 4</strong></p>
<p>Convert “<code>02/07/10</code>“, “<code>02/23/10</code>“, “<code>02/08/10</code>“, “<code>02/14/10</code>“, and<br>
“<code>02/10/10</code>“, into date objects within the variable, “<code>Exer4Dates</code>“.</p>
<p><strong>Exercise 5</strong></p>
<p>Find the mean of the date object variable “<code>Exer4Dates</code>“.</p>
<p><strong>Exercise 6</strong></p>
<p>Find the max date in “<code>Exer4Dates</code>“.</p>
<p><strong>Exercise 7</strong></p>
<p>Convert “<code>10/25/2005</code>“, and “<code>06/08/1971</code>” into a date object.</p>
<p><strong>Exercise 8</strong></p>
<p>Convert “<code>Exer4Dates</code>” to character data. Set a variable called, “<code>chrDates</code>“.</p>
<p><strong>Exercise 9</strong></p>
<p>Use the “<code>format()</code>“, and “<code>Sys.Date()</code>“, functions to print today’s date, with a format of “<code>%B %d %Y</code>“.</p>
<p><strong>Exercise 10</strong></p>
<p>Use “<code>format()</code>” and “<code>Sys.time()</code>” to print today’s date, with the time zone set to “<code>Hawaii Standard Time</code>“.</p>
<p>Image by Maklay62 (Pixabay post) [<a target="_blank" href="https://creativecommons.org/publicdomain/zero/1.0/deed.nl">CC0 Public Domain </a>], <a target="_blank" href="http://r-exercises.com/wp-content/uploads/2016/07/one-day-left-1420997__180.png">via Pixabay</a>.</p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/as-date-exercises/"></div></div><div><a data-url="http://www.r-bloggers.com/as-date-exercises/" data-counturl="http://www.r-bloggers.com/as-date-exercises/" data-count="vertical" data-text="As.Date() Exercises" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://r-exercises.com/2016/07/14/as-date-exercises/"> R-exercises</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/5GNKAD1QHZI"></a></div>