Skip to content

Commit b1e8d75

Browse files
committed
Evaluate date/time code
1 parent 7cf478a commit b1e8d75

File tree

3 files changed

+148
-82
lines changed

3 files changed

+148
-82
lines changed

02_RProgramming/Dates/index.Rmd

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ framework : io2012 # {io2012, html5slides, shower, dzslides, ...}
88
highlighter : highlight.js # {highlight.js, prettify, highlight}
99
hitheme : tomorrow #
1010
url:
11-
lib: ../../libraries
11+
lib: ../../librariesNew
1212
assets: ../../assets
1313
widgets : [mathjax] # {mathjax, quiz, bootstrap}
1414
mode : selfcontained # {standalone, draft}
@@ -95,13 +95,11 @@ p$sec
9595
Finally, there is the `strptime` function in case your dates are
9696
written in a different format
9797

98-
```r
98+
```{r}
9999
datestring <- c("January 10, 2012 10:40", "December 9, 2011 9:10")
100100
x <- strptime(datestring, "%B %d, %Y %H:%M")
101101
x
102-
## [1] "2012-01-10 10:40:00" "2011-12-09 09:10:00"
103102
class(x)
104-
## [1] "POSIXlt" "POSIXt"
105103
```
106104
I can _never_ remember the formatting strings. Check `?strptime` for details.
107105

02_RProgramming/Dates/index.html

Lines changed: 131 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,46 @@
88
<meta name="generator" content="slidify" />
99
<meta name="apple-mobile-web-app-capable" content="yes">
1010
<meta http-equiv="X-UA-Compatible" content="chrome=1">
11-
<link rel="stylesheet" href="../../libraries/frameworks/io2012/css/default.css" media="all" >
12-
<link rel="stylesheet" href="../../libraries/frameworks/io2012/phone.css"
11+
<link rel="stylesheet" href="../../librariesNew/frameworks/io2012/css/default.css" media="all" >
12+
<link rel="stylesheet" href="../../librariesNew/frameworks/io2012/css/phone.css"
1313
media="only screen and (max-device-width: 480px)" >
14-
<link rel="stylesheet" href="../../libraries/frameworks/io2012/css/slidify.css" >
15-
<link rel="stylesheet" href="../../libraries/highlighters/highlight.js/css/tomorrow.css" />
16-
<base target="_blank"> <!-- This amazingness opens all links in a new tab. -->
17-
<script data-main="../../libraries/frameworks/io2012/js/slides"
18-
src="../../libraries/frameworks/io2012/js/require-1.0.8.min.js">
14+
<link rel="stylesheet" href="../../librariesNew/frameworks/io2012/css/slidify.css" >
15+
<link rel="stylesheet" href="../../librariesNew/highlighters/highlight.js/css/tomorrow.css" />
16+
<base target="_blank"> <!-- This amazingness opens all links in a new tab. -->
17+
18+
<!-- Grab CDN jQuery, fall back to local if offline -->
19+
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js"></script>
20+
<script>window.jQuery || document.write('<script src="../../librariesNew/widgets/quiz/js/jquery.js"><\/script>')</script>
21+
<script data-main="../../librariesNew/frameworks/io2012/js/slides"
22+
src="../../librariesNew/frameworks/io2012/js/require-1.0.8.min.js">
1923
</script>
2024

21-
<link rel="stylesheet" href = "../../assets/css/custom.css">
22-
<link rel="stylesheet" href = "../../assets/css/custom.css.BACKUP.546.css">
23-
<link rel="stylesheet" href = "../../assets/css/custom.css.BASE.546.css">
24-
<link rel="stylesheet" href = "../../assets/css/custom.css.LOCAL.546.css">
25-
<link rel="stylesheet" href = "../../assets/css/custom.css.orig">
26-
<link rel="stylesheet" href = "../../assets/css/custom.css.REMOTE.546.css">
27-
<link rel="stylesheet" href = "../../assets/css/ribbons.css">
25+
2826

2927
</head>
3028
<body style="opacity: 0">
3129
<slides class="layout-widescreen">
3230

3331
<!-- LOGO SLIDE -->
34-
<!-- END LOGO SLIDE -->
32+
<slide class="title-slide segue nobackground">
33+
<aside class="gdbar">
34+
<img src="../../assets/img/bloomberg_shield.png">
35+
</aside>
36+
<hgroup class="auto-fadein">
37+
<h1>Dates and Times in R</h1>
38+
<h2></h2>
39+
<p>Roger D. Peng, Associate Professor of Biostatistics<br/>Johns Hopkins Bloomberg School of Public Health</p>
40+
</hgroup>
41+
<article></article>
42+
</slide>
3543

3644

37-
<!-- TITLE SLIDE -->
38-
<!-- Should I move this to a Local Layout File? -->
39-
<slide class="title-slide segue nobackground">
40-
<aside class="gdbar">
41-
<img src="../../assets/img/bloomberg_shield.png">
42-
</aside>
43-
<hgroup class="auto-fadein">
44-
<h1>Dates and Times in R</h1>
45-
<h2></h2>
46-
<p>Roger D. Peng, Associate Professor of Biostatistics<br/>Johns Hopkins Bloomberg School of Public Health</p>
47-
</hgroup>
48-
</slide>
49-
5045
<!-- SLIDES -->
51-
<slide class="" id="slide-1" style="background:;">
46+
<slide class="" id="slide-1" style="background:;">
5247
<hgroup>
5348
<h2>Dates and Times in R</h2>
5449
</hgroup>
55-
<article>
50+
<article data-timings="">
5651
<p>R has developed a special representation of dates and times</p>
5752

5853
<ul>
@@ -66,11 +61,11 @@ <h2>Dates and Times in R</h2>
6661
<!-- Presenter Notes -->
6762
</slide>
6863

69-
<slide class="" id="slide-2" style="background:;">
64+
<slide class="" id="slide-2" style="background:;">
7065
<hgroup>
7166
<h2>Dates in R</h2>
7267
</hgroup>
73-
<article>
68+
<article data-timings="">
7469
<p>Dates are represented by the Date class and can be coerced from a character string using the <code>as.Date()</code> function.</p>
7570

7671
<pre><code class="r">x &lt;- as.Date(&quot;1970-01-01&quot;)
@@ -86,11 +81,11 @@ <h2>Dates in R</h2>
8681
<!-- Presenter Notes -->
8782
</slide>
8883

89-
<slide class="" id="slide-3" style="background:;">
84+
<slide class="" id="slide-3" style="background:;">
9085
<hgroup>
9186
<h2>Times in R</h2>
9287
</hgroup>
93-
<article>
88+
<article data-timings="">
9489
<p>Times are represented using the <code>POSIXct</code> or the <code>POSIXlt</code> class</p>
9590

9691
<ul>
@@ -110,11 +105,11 @@ <h2>Times in R</h2>
110105
<!-- Presenter Notes -->
111106
</slide>
112107

113-
<slide class="" id="slide-4" style="background:;">
108+
<slide class="" id="slide-4" style="background:;">
114109
<hgroup>
115110
<h2>Times in R</h2>
116111
</hgroup>
117-
<article>
112+
<article data-timings="">
118113
<p>Times can be coerced from a character string using the <code>as.POSIXlt</code> or <code>as.POSIXct</code> function.</p>
119114

120115
<pre><code class="r">x &lt;- Sys.time()
@@ -132,11 +127,11 @@ <h2>Times in R</h2>
132127
<!-- Presenter Notes -->
133128
</slide>
134129

135-
<slide class="" id="slide-5" style="background:;">
130+
<slide class="" id="slide-5" style="background:;">
136131
<hgroup>
137132
<h2>Times in R</h2>
138133
</hgroup>
139-
<article>
134+
<article data-timings="">
140135
<p>You can also use the <code>POSIXct</code> format.</p>
141136

142137
<pre><code class="r">x &lt;- Sys.time()
@@ -155,19 +150,26 @@ <h2>Times in R</h2>
155150
<!-- Presenter Notes -->
156151
</slide>
157152

158-
<slide class="" id="slide-6" style="background:;">
153+
<slide class="" id="slide-6" style="background:;">
159154
<hgroup>
160155
<h2>Times in R</h2>
161156
</hgroup>
162-
<article>
163-
<p>Finally, there is the <code>strptime</code> function in case your dates are written in a different format</p>
157+
<article data-timings="">
158+
<p>Finally, there is the <code>strptime</code> function in case your dates are
159+
written in a different format</p>
164160

165-
<pre><code class="r">datestring &lt;- c(&quot;January 10, 2012 10:40&quot;, &quot;December 9, 2011
161+
<pre><code class="r">datestring &lt;- c(&quot;January 10, 2012 10:40&quot;, &quot;December 9, 2011 9:10&quot;)
166162
x &lt;- strptime(datestring, &quot;%B %d, %Y %H:%M&quot;)
167163
x
168-
## [1] &quot;2012-01-10 10:40:00&quot; &quot;2011-12-09 09:10:00&quot;
169-
class(x)
170-
## [1] &quot;POSIXlt&quot; &quot;POSIXt&quot;
164+
</code></pre>
165+
166+
<pre><code>## [1] &quot;2012-01-10 10:40:00 EST&quot; &quot;2011-12-09 09:10:00 EST&quot;
167+
</code></pre>
168+
169+
<pre><code class="r">class(x)
170+
</code></pre>
171+
172+
<pre><code>## [1] &quot;POSIXlt&quot; &quot;POSIXt&quot;
171173
</code></pre>
172174

173175
<p>I can <em>never</em> remember the formatting strings. Check <code>?strptime</code> for details.</p>
@@ -176,11 +178,11 @@ <h2>Times in R</h2>
176178
<!-- Presenter Notes -->
177179
</slide>
178180

179-
<slide class="" id="slide-7" style="background:;">
181+
<slide class="" id="slide-7" style="background:;">
180182
<hgroup>
181183
<h2>Operations on Dates and Times</h2>
182184
</hgroup>
183-
<article>
185+
<article data-timings="">
184186
<p>You can use mathematical operations on dates and times. Well, really just + and -. You can do comparisons too (i.e. ==, &lt;=)</p>
185187

186188
<pre><code class="r">x &lt;- as.Date(&quot;2012-01-01&quot;)
@@ -198,11 +200,11 @@ <h2>Operations on Dates and Times</h2>
198200
<!-- Presenter Notes -->
199201
</slide>
200202

201-
<slide class="" id="slide-8" style="background:;">
203+
<slide class="" id="slide-8" style="background:;">
202204
<hgroup>
203205
<h2>Operations on Dates and Times</h2>
204206
</hgroup>
205-
<article>
207+
<article data-timings="">
206208
<p>Even keeps track of leap years, leap seconds, daylight savings, and time zones.</p>
207209

208210
<pre><code class="r">x &lt;- as.Date(&quot;2012-03-01&quot;) y &lt;- as.Date(&quot;2012-02-28&quot;)
@@ -218,11 +220,11 @@ <h2>Operations on Dates and Times</h2>
218220
<!-- Presenter Notes -->
219221
</slide>
220222

221-
<slide class="" id="slide-9" style="background:;">
223+
<slide class="" id="slide-9" style="background:;">
222224
<hgroup>
223225
<h2>Summary</h2>
224226
</hgroup>
225-
<article>
227+
<article data-timings="">
226228
<ul>
227229
<li>Dates and times have special classes in R that allow for numerical and statistical calculations</li>
228230
<li>Dates use the <code>Date</code> class</li>
@@ -236,34 +238,89 @@ <h2>Summary</h2>
236238

237239
<slide class="backdrop"></slide>
238240
</slides>
239-
240-
<!--[if IE]>
241+
<div class="pagination pagination-small" id='io2012-ptoc' style="display:none;">
242+
<ul>
243+
<li>
244+
<a href="#" target="_self" rel='tooltip'
245+
data-slide=1 title='Dates and Times in R'>
246+
1
247+
</a>
248+
</li>
249+
<li>
250+
<a href="#" target="_self" rel='tooltip'
251+
data-slide=2 title='Dates in R'>
252+
2
253+
</a>
254+
</li>
255+
<li>
256+
<a href="#" target="_self" rel='tooltip'
257+
data-slide=3 title='Times in R'>
258+
3
259+
</a>
260+
</li>
261+
<li>
262+
<a href="#" target="_self" rel='tooltip'
263+
data-slide=4 title='Times in R'>
264+
4
265+
</a>
266+
</li>
267+
<li>
268+
<a href="#" target="_self" rel='tooltip'
269+
data-slide=5 title='Times in R'>
270+
5
271+
</a>
272+
</li>
273+
<li>
274+
<a href="#" target="_self" rel='tooltip'
275+
data-slide=6 title='Times in R'>
276+
6
277+
</a>
278+
</li>
279+
<li>
280+
<a href="#" target="_self" rel='tooltip'
281+
data-slide=7 title='Operations on Dates and Times'>
282+
7
283+
</a>
284+
</li>
285+
<li>
286+
<a href="#" target="_self" rel='tooltip'
287+
data-slide=8 title='Operations on Dates and Times'>
288+
8
289+
</a>
290+
</li>
291+
<li>
292+
<a href="#" target="_self" rel='tooltip'
293+
data-slide=9 title='Summary'>
294+
9
295+
</a>
296+
</li>
297+
</ul>
298+
</div> <!--[if IE]>
241299
<script
242300
src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js">
243301
</script>
244302
<script>CFInstall.check({mode: 'overlay'});</script>
245303
<![endif]-->
246304
</body>
247-
<!-- Grab CDN jQuery, fall back to local if offline -->
248-
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js"></script>
249-
<script>window.jQuery || document.write('<script src="../../libraries/widgets/quiz/js/jquery-1.7.min.js"><\/script>')</script>
250-
<!-- Load Javascripts for Widgets -->
251-
<!-- MathJax: Fall back to local if CDN offline but local image fonts are not supported (saves >100MB) -->
252-
<script type="text/x-mathjax-config">
253-
MathJax.Hub.Config({
254-
tex2jax: {
255-
inlineMath: [['$','$'], ['\\(','\\)']],
256-
processEscapes: true
257-
}
258-
});
259-
</script>
260-
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
261-
<!-- <script src="https://c328740.ssl.cf1.rackcdn.com/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
262-
</script> -->
263-
<script>window.MathJax || document.write('<script type="text/x-mathjax-config">MathJax.Hub.Config({"HTML-CSS":{imageFont:null}});<\/script><script src="../../libraries/widgets/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"><\/script>')
305+
<!-- Load Javascripts for Widgets -->
306+
307+
<!-- MathJax: Fall back to local if CDN offline but local image fonts are not supported (saves >100MB) -->
308+
<script type="text/x-mathjax-config">
309+
MathJax.Hub.Config({
310+
tex2jax: {
311+
inlineMath: [['$','$'], ['\\(','\\)']],
312+
processEscapes: true
313+
}
314+
});
315+
</script>
316+
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
317+
<!-- <script src="https://c328740.ssl.cf1.rackcdn.com/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
318+
</script> -->
319+
<script>window.MathJax || document.write('<script type="text/x-mathjax-config">MathJax.Hub.Config({"HTML-CSS":{imageFont:null}});<\/script><script src="../../librariesNew/widgets/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"><\/script>')
264320
</script>
265321
<!-- LOAD HIGHLIGHTER JS FILES -->
266-
<script src="../../libraries/highlighters/highlight.js/highlight.pack.js"></script>
267-
<script>hljs.initHighlightingOnLoad();</script>
268-
<!-- DONE LOADING HIGHLIGHTER JS FILES -->
269-
</html>
322+
<script src="../../librariesNew/highlighters/highlight.js/highlight.pack.js"></script>
323+
<script>hljs.initHighlightingOnLoad();</script>
324+
<!-- DONE LOADING HIGHLIGHTER JS FILES -->
325+
326+
</html>

02_RProgramming/Dates/index.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ framework : io2012 # {io2012, html5slides, shower, dzslides, ...}
88
highlighter : highlight.js # {highlight.js, prettify, highlight}
99
hitheme : tomorrow #
1010
url:
11-
lib: ../../libraries
11+
lib: ../../librariesNew
1212
assets: ../../assets
1313
widgets : [mathjax] # {mathjax, quiz, bootstrap}
1414
mode : selfcontained # {standalone, draft}
@@ -92,14 +92,25 @@ p$sec
9292

9393
## Times in R
9494

95-
Finally, there is the `strptime` function in case your dates are written in a different format
95+
Finally, there is the `strptime` function in case your dates are
96+
written in a different format
97+
9698

9799
```r
98-
datestring <- c("January 10, 2012 10:40", "December 9, 2011
100+
datestring <- c("January 10, 2012 10:40", "December 9, 2011 9:10")
99101
x <- strptime(datestring, "%B %d, %Y %H:%M")
100102
x
101-
## [1] "2012-01-10 10:40:00" "2011-12-09 09:10:00"
103+
```
104+
105+
```
106+
## [1] "2012-01-10 10:40:00 EST" "2011-12-09 09:10:00 EST"
107+
```
108+
109+
```r
102110
class(x)
111+
```
112+
113+
```
103114
## [1] "POSIXlt" "POSIXt"
104115
```
105116
I can _never_ remember the formatting strings. Check `?strptime` for details.

0 commit comments

Comments
 (0)