this looks quite beneficial.<br><br>I find myself doing the following a lot<br><br>dt$Date= as.integer(format(dt$Date, "%Y%m%d"))<br><br>So this should take care of this problem.<br><br>I'll see where I can use this and try to test it out,<br>
Rob<br><br><div class="gmail_quote">On Mon, Apr 12, 2010 at 4:08 PM, Short, Tom <span dir="ltr"><<a href="mailto:TShort@epri.com">TShort@epri.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
See enclosed for a draft of classes that implement dates and times with<br>
integer storage. The IDate class is a simple wrapper around the Date<br>
class that tries to keep an integer storage format. The ITime class, the<br>
time of day, is stored as the number of seconds in a day.<br>
<br>
Because IDate and ITime are stored as integers with ranges less than<br>
100,000, data.table indexing and sorting is fast. Also included are<br>
conversions to and from POSIXct and chron formats.<br>
<br>
Comments and tests are welcome.<br>
<br>
Examples:<br>
<br>
> (t <- as.ITime("10:45:04"))<br>
[1] "10:45:04"<br>
> (d <- as.IDate("2001-01-01"))<br>
[1] "2001-01-01"<br>
><br>
> datetime <- seq(as.POSIXct("2001-01-01"),<br>
+ as.POSIXct("2001-01-03"), by = "5 hour")<br>
><br>
> (a <- data.table(IDateTime(datetime), a = rep(1:2, 5),<br>
+ key = "a,date,time"))<br>
date time a<br>
[1,] 2001-01-01 00:00:00 1<br>
[2,] 2001-01-01 10:00:00 1<br>
[3,] 2001-01-02 06:00:00 1<br>
[4,] 2001-01-02 16:00:00 1<br>
[5,] 2001-01-02 20:00:00 1<br>
[6,] 2001-01-01 05:00:00 2<br>
[7,] 2001-01-01 15:00:00 2<br>
[8,] 2001-01-02 01:00:00 2<br>
[9,] 2001-01-02 11:00:00 2<br>
[10,] 2001-01-03 21:00:00 2<br>
><br>
> a[, mean(a), by = "date"]<br>
date V1<br>
[1,] 2001-01-01 1.5<br>
[2,] 2001-01-02 1.4<br>
[3,] 2001-01-03 2.0<br>
><br>
> as.POSIXct(af$date, af$time)<br>
[1] "2001-01-01 00:00:00 EST" "2001-01-01 18:00:00 EST"<br>
[3] "2001-01-02 12:00:00 EST" "2001-01-01 06:00:00 EST"<br>
[5] "2001-01-02 00:00:00 EST" "2001-01-02 18:00:00 EST"<br>
[7] "2001-01-01 12:00:00 EST" "2001-01-02 06:00:00 EST"<br>
[9] "2001-01-03 00:00:00 EST"<br>
<br>
- Tom<br>
<font color="#888888"><br>
Tom Short<br>
Electric Power Research Institute (EPRI)<br>
<br>
<br>
</font><br>_______________________________________________<br>
datatable-help mailing list<br>
<a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br>
<br></blockquote></div><br>