I discovered that if I wanted control of the dates on the x axis I had to convert the IDate to as.POSIXct as well otherwise strange and undesirable things started happening - for instance all the dates were the same if I tried to format the dates in a particular way. So here is what I finished with my original data set.<div>
<br></div><div><div>qplot(data=<a href="http://ape.ph">ape.ph</a>,x=as.POSIXct(date,tz="EST"), y=as.POSIXct(timei,tz="EST")) + </div><div> scale_y_datetime(name="time",format="%H:%M") +</div>
<div> scale_x_datetime(name="November",major="1 day", format = "%a %d")</div><div><br clear="all">Farrel Buchinsky<br>Google Voice Tel: (412) 567-7870<br><br>
<br><br><div class="gmail_quote">On Fri, Dec 16, 2011 at 10:35, Farrel Buchinsky <span dir="ltr"><<a href="mailto:fjbuch@gmail.com">fjbuch@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>Dear Matthew</div><div><br></div><div>Thank you very much for your help.</div><div>I found something fascinating. I do not know the details of POSIXct and iTime but look at this.</div><div><br></div><div><div>library(data.table)</div>
<div>library(ggplot2)</div></div><div><br></div><div><div>datetimes <- c("2011 NOV18 09:29:16", "2011 NOV18 10:42:40", "2011 NOV18 10:47:12", </div><div>"2011 NOV18 11:06:01", "2011 NOV18 11:35:34", "2011 NOV18 11:51:09", </div>
<div>"2011 NOV18 12:23:16", "2011 NOV18 12:30:01", "2011 NOV18 12:34:28", </div><div>"2011 NOV18 12:51:45", "2011 NOV18 12:56:37", "2011 NOV18 13:28:17", </div>
<div>
"2011 NOV18 13:37:41", "2011 NOV18 13:49:07", "2011 NOV18 14:47:04", </div><div>"2011 NOV18 15:16:39", "2011 NOV18 15:17:10", "2011 NOV18 15:19:19", </div><div>
"2011 NOV19 08:28:00", "2011 NOV19 09:20:55", "2011 NOV19 10:41:25", </div>
<div>"2011 NOV19 10:41:41", "2011 NOV19 12:53:15", "2011 NOV20 11:22:59", </div><div>"2011 NOV20 19:53:25", "2011 NOV21 07:16:35", "2011 NOV21 08:50:45", </div>
<div>
"2011 NOV21 09:32:59", "2011 NOV21 09:43:01", "2011 NOV21 10:29:52", </div><div>"2011 NOV21 10:34:23", "2011 NOV21 10:37:09", "2011 NOV21 10:55:18", </div><div>
"2011 NOV21 11:43:46", "2011 NOV21 11:46:50", "2011 NOV21 12:10:16", </div>
<div>"2011 NOV21 12:16:44", "2011 NOV21 13:53:42", "2011 NOV21 13:53:43", </div><div>"2011 NOV21 14:06:06", "2011 NOV21 14:23:39", "2011 NOV21 15:14:21", </div>
<div>
"2011 NOV21 15:35:53", "2011 NOV21 15:46:29", "2011 NOV21 15:49:37", </div><div>"2011 NOV21 16:45:32", "2011 NOV21 20:36:31", "2011 NOV22 08:56:03", </div><div>
"2011 NOV22 09:33:12", "2011 NOV22 09:39:52", "2011 NOV22 10:40:46", </div>
<div>"2011 NOV22 11:19:48", "2011 NOV22 11:23:32", "2011 NOV22 12:04:16", </div><div>"2011 NOV22 12:07:04", "2011 NOV22 12:23:31", "2011 NOV22 12:28:54", </div>
<div>
"2011 NOV22 12:31:14", "2011 NOV22 12:53:31", "2011 NOV22 12:54:11", </div><div>"2011 NOV22 13:41:54", "2011 NOV22 15:34:11", "2011 NOV23 07:03:44", </div><div>
"2011 NOV23 07:04:57", "2011 NOV23 08:01:42", "2011 NOV23 08:37:14", </div>
<div>"2011 NOV23 08:57:55", "2011 NOV23 09:00:34", "2011 NOV23 09:10:38", </div><div>"2011 NOV23 09:21:19", "2011 NOV23 09:23:58", "2011 NOV23 10:48:10", </div>
<div>
"2011 NOV23 11:23:58", "2011 NOV23 11:49:14", "2011 NOV23 12:19:44", </div><div>"2011 NOV23 12:31:34", "2011 NOV23 12:48:00", "2011 NOV23 13:22:08", </div><div>
"2011 NOV23 13:30:36", "2011 NOV23 14:01:56", "2011 NOV23 14:38:15", </div>
<div>"2011 NOV23 14:54:02", "2011 NOV23 15:33:31", "2011 NOV23 15:49:12", </div><div>"2011 NOV25 09:21:42", "2011 NOV25 09:22:25", "2011 NOV25 09:24:22", </div>
<div>
"2011 NOV25 10:07:42", "2011 NOV25 15:03:15", "2011 NOV28 08:12:32", </div><div>"2011 NOV28 09:20:39", "2011 NOV28 09:26:09", "2011 NOV28 10:25:47", </div><div>
"2011 NOV28 11:19:40", "2011 NOV28 11:54:54", "2011 NOV28 14:33:53", </div>
<div>"2011 NOV28 15:08:25", "2011 NOV28 15:09:25", "2011 NOV28 15:23:07", </div><div>"2011 NOV28 15:23:30", "2011 NOV28 15:50:35", "2011 NOV29 08:22:39", </div>
<div>
"2011 NOV29 09:08:51", "2011 NOV29 09:10:15", "2011 NOV29 10:44:17", </div><div>"2011 NOV29 11:32:05", "2011 NOV29 12:00:52", "2011 NOV29 12:32:48", </div><div>
"2011 NOV29 13:21:50", "2011 NOV29 13:22:12", "2011 NOV29 13:22:38", </div>
<div>"2011 NOV29 13:23:35", "2011 NOV29 13:28:38", "2011 NOV29 13:29:44", </div><div>"2011 NOV29 13:30:25", "2011 NOV29 13:32:13", "2011 NOV29 13:33:28", </div>
<div>
"2011 NOV29 13:35:59", "2011 NOV29 13:37:01", "2011 NOV29 13:39:37", </div><div>"2011 NOV29 13:41:33", "2011 NOV29 14:08:07", "2011 NOV29 14:09:53", </div><div>
"2011 NOV29 14:13:15", "2011 NOV29 14:16:16", "2011 NOV29 14:17:32", </div>
<div>"2011 NOV29 14:37:05", "2011 NOV29 14:59:51", "2011 NOV29 14:59:51", </div><div>"2011 NOV29 14:59:54", "2011 NOV29 15:00:10", "2011 NOV29 15:13:22", </div>
<div>
"2011 NOV29 16:09:50", "2011 NOV29 16:10:17", "2011 NOV29 16:31:14", </div><div>"2011 NOV29 16:43:20", "2011 NOV30 09:22:09", "2011 NOV30 10:19:21", </div><div>
"2011 NOV30 11:42:04", "2011 NOV30 11:50:11", "2011 NOV30 12:21:11", </div>
<div>"2011 NOV30 13:06:39")</div><div><br></div><div>datetimes <- strptime(datetimes,"%Y %b%d %H:%M:%S")</div><div>dtdt <- IDateTime(datetimes)</div><div>setkey(x=dtdt,idate,itime)</div><div>plot(dtdt$idate,dtdt$itime)#works although I still need to figure out how to get times that I, as a human, understand</div>
<div>qplot(x=dtdt$idate,y=dtdt$itime) # gives an error</div><div><br></div><div>#Error in as.data.frame.default(x[[i]], optional = TRUE) : </div><div class="im"><div># cannot coerce class '"ITime"' into a data.frame</div>
<div><br></div></div><div>dtdt[,qplot(idate,itime)]#same error</div><div><br></div><div><div><br></div><div>qplot(x=dtdt$idate,y=as.POSIXct(dtdt$itime,tz="EST")) #have to specify the time zone otherwise I got evertying at UTC</div>
</div></div><div><br></div><div><b>Clearly this has something to do with the way ggplot wants its data. Plot handled it but qplot did not.</b></div><span class="HOEnZb"><font color="#888888"><div><br></div><div><br></div>
Farrel Buchinsky<img src="cid:517@goomoji.gmail" style="margin-top:0px;margin-right:0.2ex;margin-bottom:0px;margin-left:0.2ex;vertical-align:middle" goomoji="517"></font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br><br><div class="gmail_quote">On Fri, Dec 16, 2011 at 03:50, Matthew Dowle <span dir="ltr"><<a href="mailto:mdowle@mdowle.plus.com" target="_blank">mdowle@mdowle.plus.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi.<br>
<br>
You should be able to add more than one column in one step using := by<br>
setting with=FALSE like this :<br>
<br>
> DT = data.table(a=1:3,b=4:6)<br>
> DT<br>
a b<br>
[1,] 1 4<br>
[2,] 2 5<br>
[3,] 3 6<br>
> DT[,c("newcol1","newcol2"):=list(7:9,3.14)]<br>
Error in `[.data.table`(DT, , `:=`(c("newcol1", "newcol2"),<br>
list(7:9, :<br>
LHS of := must be a single column name, when with=TRUE. When<br>
with=FALSE the LHS may be a vector of column names or positions.<br>
<br>
so set with=FALSE :<br>
<br>
> DT[,c("newcol1","newcol2"):=list(7:9,3.14),with=FALSE]<br>
Error in `[.data.table`(DT, , `:=`(c("newcol1", "newcol2"),<br>
list(7:9, :<br>
Logical error. Can only add new columns one at a time currently<br>
><br>
<br>
I intended that to work so I'll take a look. But, the intention is at<br>
some point to enable this :<br>
<br>
DT[,{ newcol1 := ....<br>
newcol2 := ....<br>
newcol3 := newcol1 + newcol2<br>
}, by=... ]<br>
<br>
where not only can you add multiple columns by reference and by group,<br>
but they can 'see' previous columns just added. That's going to be quite<br>
tricky to implement so don't hold your breath!<br>
<br>
In the meantime it's either one at a time with :=, or use (slower) [<-<br>
method to add multiple columns (via at least one full table copy).<br>
<br>
Re plotting, I'm hoping to learn ggplot2 myself soon, so bear that in<br>
mind, but this is the way I thought should work :<br>
<br>
<a href="http://ape.ph" target="_blank">ape.ph</a>[,qplot(date, timei)]<br>
<br>
If that gives the same error I'm not sure why it would try to coerce<br>
ITime into a data.frame. Does anyone else know? If you can provide some<br>
example data it might help save us time to reproduce it.<br>
<br>
Matthew<br>
<div><div><br>
<br>
<br>
On Thu, 2011-12-15 at 19:25 -0500, Farrel Buchinsky wrote:<br>
> I was able to take a column of dates and times that looked like this<br>
><br>
> 2011 NOV18 09:29:16<br>
><br>
><br>
> I then tried this<br>
><br>
> <a href="http://ape.ph" target="_blank">ape.ph</a>[,date:=IDateTime(strptime(<a href="http://ape.ph" target="_blank">ape.ph</a>$time,"%Y %b%d %H:%M:%S"))[[1]]]<br>
> <a href="http://ape.ph" target="_blank">ape.ph</a>[,timei:=as.ITime(strptime(<a href="http://ape.ph" target="_blank">ape.ph</a>$time,"%Y %b%d %H:%M:%S"))]<br>
><br>
><br>
> I had to create one column called date to accept the first column of<br>
> the IDateTime output. There does not appear to be a way to use the<br>
> IDateTime function and take both of its columns and stick it into the<br>
> data.table since one can only add one new column at a time as far as I<br>
> can tell. Anyway, I then created a variable timei to accept the time.<br>
><br>
><br>
> I wanted to plot the times that something happened on the y axis and<br>
> then on the x axis I wanted to have the various dates<br>
><br>
><br>
> library(ggplot2)<br>
> qplot(<a href="http://ape.ph" target="_blank">ape.ph</a>[,date], <a href="http://ape.ph" target="_blank">ape.ph</a>[,timei])<br>
><br>
><br>
> but alas I got this<br>
><br>
><br>
> Error in as.data.frame.default(x[[i]], optional = TRUE) :<br>
> cannot coerce class '"ITime"' into a data.frame<br>
><br>
><br>
> I am eventually hoping for this<br>
> qplot(<a href="http://ape.ph" target="_blank">ape.ph</a>[,date], <a href="http://ape.ph" target="_blank">ape.ph</a>[,timei]) +<br>
> scale_y_datetime(format="%H:%M:%S") +<br>
> xlab("Day") + ylab("Hour")<br>
><br>
><br>
> Do you have any examples of dates and times used in a data.table and<br>
> then being used to plot graphs? I would love to see some examples. I<br>
> could not find any<br>
><br>
><br>
><br>
><br>
> Farrel Buchinsky<br>
> Google Voice Tel: <a href="tel:%28412%29%20567-7870" value="+14125677870" target="_blank">(412) 567-7870</a><br>
><br>
><br>
</div></div>> _______________________________________________<br>
> datatable-help mailing list<br>
> <a href="mailto:datatable-help@lists.r-forge.r-project.org" target="_blank">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>
<br>
</blockquote></div><br>
</div></div></blockquote></div><br></div></div>