[datatable-help] IDate somehow gets converted to numeric?
Short, Tom
TShort at epri.com
Fri Aug 5 00:34:15 CEST 2011
Chris, I can't replicate that. What versions of R, data.table, and plyr
are you using?
As an aside, why do you need ddply in the first place? It seems
data.tables would be faster for that sort of thing.
- Tom
> -----Original Message-----
> From: datatable-help-bounces at r-forge.wu-wien.ac.at
> [mailto:datatable-help-bounces at r-forge.wu-wien.ac.at] On
> Behalf Of Chris Neff
> Sent: Thursday, August 04, 2011 18:13
> To: datatable-help at lists.r-forge.r-project.org
> Subject: [datatable-help] IDate somehow gets converted to numeric?
>
> 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
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/d
atatable-help
>
More information about the datatable-help
mailing list