Purpose
To explore lubridate , a package which is supposed to make datetime functions easier to perform.

Also,today I realized while reading creative habit, by Twyala Tharp that she readed stuff archealogically. This means you start from backwards and you pick up stuff as you go along backwards.

For somereason this made tremendous sense to me for learning about package I have logged in 1148 hours in R and have never programmed a package.

The gap between coding functions and creating a package was something I found it difficult to cross.Hence I am following Twyala Tharp’s idea of going backwards.

I am going to learn the package lubridate. Learn the structure and understand what’s behind it.

This lubridate package could be the thing useful to learn github.

First to begin with, Let me do some deliberate practice using lubridate. I will go in with casella post lunch.

Using lubridate

> library(lubridate)
> date1 <- dmy("01-01-2010")
> print(date1)
[1] "2010-01-01 UTC"
> print(month(date1))
[1] 1
> month(date1) <- 2
> print(date1)
[1] "2010-02-01 UTC"
> date1 - days(1)
[1] "2010-01-31 UTC"

Using base date classes

> date <- as.POSIXct("01-01-2010", format = "%d-%m-%Y", tz = "UTC")
> as.numeric(format(date, "%m"))
[1] 1
> date2 <- as.POSIXct("2010-01-01", format = "%Y-%m-%d", tz = "UTC")
> x <- c("09/01/01", "09/01/02", "09/01/03")
> ymd(x)
[1] "2009-01-01 UTC" "2009-01-02 UTC" "2009-01-03 UTC"
> x <- c("09.01.01", "09.01.02", "09.01.03")
> ymd(x)
[1] "2009-01-01 UTC" "2009-01-02 UTC" "2009-01-03 UTC"

Snippets

> date <- now()
> year(date)
[1] 2011
> month(date)
[1] 7
> week(date)
[1] 30
> yday(date)
[1] 209
> mday(date)
[1] 28
> wday(date)
[1] 5
> hour(date)
[1] 0
> minute(date)
[1] 4
> second(date)
[1] 6
> tz(date)
[1] ""
  1. Extremely useful in filling in the minutes in the data
> dates <- ymd_hms("2010-01-01 01:00:00", "2010-01-01 01:30:00")
> minute(dates) <- 15
> dates
[1] "2010-01-01 01:15:00 UTC" "2010-01-01 01:15:00 UTC"
> start_2012 <- ymd_hms("2012-01-01 12:00:00")