[datatable-help] Auto-convert characters to factors when settings keys?

Matthew Dowle mdowle at mdowle.plus.com
Mon Aug 30 00:16:54 CEST 2010



setkey now coerces character to factor (as Steve suggested), and double to
integer (provided they are all.equal).


Steve Lianoglou wrote:
> 
> Would it make sense to autoconvert characters to factors when setting
> a character column as a key?
> df <- data.frame(a=LETTERS[1:10], b=1:10, stringsAsFactors=F)
> dt <- data.table(df)
> key(dt) <- 'a'
>   All keyed columns must be storage mode integer
> dt <- data.table(df, key='a')
> Error in setkey(value, a) :
>   All keyed columns must be storage mode integer
> 

That became bug #953, now fixed with tests 215-219 added.

> df <- data.frame(a=LETTERS[1:10], b=1:10, stringsAsFactors=F)
> dt <- data.table(df)
> key(dt) <- 'a'
> dt["C"]
     a b
[1,] C 3


Matthew


-- 
View this message in context: http://r.789695.n4.nabble.com/Auto-convert-characters-to-factors-when-settings-keys-tp2315281p2399401.html
Sent from the datatable-help mailing list archive at Nabble.com.


More information about the datatable-help mailing list