[datatable-help] Does setkey silently coerce numeric to integer?
Matthew Dowle
mdowle at mdowle.plus.com
Thu Oct 14 22:04:32 CEST 2010
Yes, setkey() auto-coercing double to integer is a deliberate
convenience feature. It's not so much for binary search but radix
sorting that integer is required (see slide 3 of the July presentation).
>From NEWS for 1.5 :
o setkey() now coerces character to factor and double to
integer (provided they are all.equal), fixing bug #953.
Thanks to Steve Lianoglou for reporting.
Matthew
On Sun, 2010-10-10 at 14:56 -0700, djmuseR wrote:
> The documentation says that all variables serving as keys in a data table
> must be of storage mode integer, so the short answer to your question is
> yes. Integers and factors are 'naturally' of storage mode factor in R,
> character variables assigned as keys are coerced to factor so that they have
> storage mode integer and numeric variables assigned as keys are coerced to
> integer for the same reason. I believe the reason for this (which is
> explained in the vignette and FAQ, if memory serves) is to make binary
> search as efficient as possible.
>
> HTH,
> Dennis
More information about the datatable-help
mailing list