R data.table roll="nearest" not actually nearest

Viewed 986

Given the following data.tables I'm surprised to see the 5.9 index matching with 5 rather than 6.

I don't quite understand what's going on.

dat <- data.table(index = c(4.3, 5.9, 1.2), datval = runif(3)+10, 
datstuff="test")
reference <- data.table(index = 1:10, refjunk = "junk", refval = runif(10))

dat[, dat_index := index]
reference[dat, roll="nearest", on="index"]

I would expect to see 3 rows with the index==6 row in reference being matched with the index==5.9 row in dat, at least for my understanding on nearest.

Is this the expected behaviour?

Using R 3.3.2, data.table 1.10.4

1 Answers
Related