r - data.table backward rolling join between integer and numeric columns -
came across unexpected behavior today involving data.table's rolling join. want rolling join between integer type column , numeric type column. forward roll works expected backwards roll doesn't.
dt1<-data.table(x=as.integer(c(1,2))) dt2<-data.table(x=c(1.5)) setkey(dt1, "x") setkey(dt2, "x") dt1[dt2, roll=true] #expected behavior x 1: 1 dt1[dt2, roll=-inf] #unexpected behavior x 1: 1
is bug or behavior documented? guessing looks data.table casting numeric column integer internally instead of casting integer column numeric.
this expected behavior, albeit buried warning. happens dt2$x
coerced integer, neither of rolls doing , it's straight merge value of 1.
to see warning use verbose=true
:
dt1[dt2, verbose = true] #coercing 'double' column i.'x' 'integer' match type of x.'x'. please avoid coercion efficiency. #starting bmerge ...done in 0 secs # x #1: 1
Comments
Post a Comment