[datatable-help] IDate somehow gets converted to numeric?

Chris Neff caneff at gmail.com
Fri Aug 5 12:50:10 CEST 2011


Plyr is 1.6 (latest CRAN), data.table is 1.6.3 (latest CRAN), and R is
2.12.1 (can't have a newer version due to custom work build).

The reason I'm doing it is more for code readability than anything.
If multiple := was supported already I could make what I'm doing look
not too bad, but as it is now what I'm doing is more obvious as a plyr
statement. Namely I am doing a by command that changes the results of
multiple variables at once (rescaling them), so if I were to do it
with data.table I'd have to redo the by part for each variable
separately. And the data at for this isn't really so big to worry
about it at the moment.

Digging through the plyr code there isn't anything obvious that would
cause this to happen. And I'm unable to get this bug to happen any
other way so far.


On 4 August 2011 18:34, Short, Tom <TShort at epri.com> wrote:
> 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