[datatable-help] IDate somehow gets converted to numeric?
Chris Neff
caneff at gmail.com
Fri Aug 5 00:13:28 CEST 2011
This was kind of hard to track down. An example:
> DT <- data.table(date=as.IDate(rep("2010-01-01",10)),x=1:10)
> DT <- as.data.frame(DT)
> str(DT)
'data.frame': 10 obs. of 2 variables:
$ date:Classes 'IDate', 'Date' int [1:10] 14610 14610 14610 14610
14610 14610 14610 14610 14610 14610
$ x : int 1 2 3 4 5 6 7 8 9 10
> DT2 <- ddply(DT, c("date", "x"), identity)
> str(DT2)
'data.frame': 10 obs. of 2 variables:
$ date:Classes 'IDate', 'Date' num [1:10] 14610 14610 14610 14610 14610 ...
$ x : int 1 2 3 4 5 6 7 8 9 10
As you can see int has changed to num here. If I try to convert back
to a data table and key on date again:
> DT2 <- as.data.table(DT2)
> key(DT2)="date"
Error in setkey("x", value) :
Column 'date' cannot be auto converted to integer without losing information.
Whereas converting DT back to a data table and keying on date works fine. Bug?
-Chris
More information about the datatable-help
mailing list