R has developed a special representation of dates and times
-
@@ -66,11 +61,11 @@
diff --git a/02_RProgramming/Dates/index.Rmd b/02_RProgramming/Dates/index.Rmd
index 52462db80..d435714c4 100644
--- a/02_RProgramming/Dates/index.Rmd
+++ b/02_RProgramming/Dates/index.Rmd
@@ -8,7 +8,7 @@ framework : io2012 # {io2012, html5slides, shower, dzslides, ...}
highlighter : highlight.js # {highlight.js, prettify, highlight}
hitheme : tomorrow #
url:
- lib: ../../libraries
+ lib: ../../librariesNew
assets: ../../assets
widgets : [mathjax] # {mathjax, quiz, bootstrap}
mode : selfcontained # {standalone, draft}
@@ -95,13 +95,11 @@ p$sec
Finally, there is the `strptime` function in case your dates are
written in a different format
-```r
+```{r}
datestring <- c("January 10, 2012 10:40", "December 9, 2011 9:10")
x <- strptime(datestring, "%B %d, %Y %H:%M")
x
-## [1] "2012-01-10 10:40:00" "2011-12-09 09:10:00"
class(x)
-## [1] "POSIXlt" "POSIXt"
```
I can _never_ remember the formatting strings. Check `?strptime` for details.
diff --git a/02_RProgramming/Dates/index.html b/02_RProgramming/Dates/index.html
index b0fe8124f..c3d93923d 100644
--- a/02_RProgramming/Dates/index.html
+++ b/02_RProgramming/Dates/index.html
@@ -8,51 +8,46 @@
-
-
+
-
-
-
Roger D. Peng, Associate Professor of Biostatistics
Johns Hopkins Bloomberg School of Public Health
Roger D. Peng, Associate Professor of Biostatistics
Johns Hopkins Bloomberg School of Public Health
R has developed a special representation of dates and times
Dates are represented by the Date class and can be coerced from a character string using the as.Date()
function.
x <- as.Date("1970-01-01")
@@ -86,11 +81,11 @@ Dates in R
Times are represented using the POSIXct
or the POSIXlt
class
Times can be coerced from a character string using the as.POSIXlt
or as.POSIXct
function.
x <- Sys.time()
@@ -132,11 +127,11 @@ Times in R
You can also use the POSIXct
format.
x <- Sys.time()
@@ -155,19 +150,26 @@ Times in R
Finally, there is the strptime
function in case your dates are written in a different format
Finally, there is the strptime
function in case your dates are
+written in a different format
datestring <- c("January 10, 2012 10:40", "December 9, 2011
+datestring <- c("January 10, 2012 10:40", "December 9, 2011 9:10")
x <- strptime(datestring, "%B %d, %Y %H:%M")
x
-## [1] "2012-01-10 10:40:00" "2011-12-09 09:10:00"
-class(x)
-## [1] "POSIXlt" "POSIXt"
+
+
+## [1] "2012-01-10 10:40:00 EST" "2011-12-09 09:10:00 EST"
+
+
+class(x)
+
+
+## [1] "POSIXlt" "POSIXt"
I can never remember the formatting strings. Check ?strptime
for details.
@@ -176,11 +178,11 @@ Times in R
You can use mathematical operations on dates and times. Well, really just + and -. You can do comparisons too (i.e. ==, <=)
x <- as.Date("2012-01-01")
@@ -198,11 +200,11 @@ Operations on Dates and Times
Even keeps track of leap years, leap seconds, daylight savings, and time zones.
x <- as.Date("2012-03-01") y <- as.Date("2012-02-28")
@@ -218,11 +220,11 @@ Operations on Dates and Times
Date
class