Skip to content

shift negative n unexpected results for double #3335

@jangorecki

Description

@jangorecki

Looks like negative n in shift functions works fine for integers but not doubles

library(data.table)
set.seed(108)
x=sample(5)
all.equal(shift(x, 1), shift(x, type="lag"))
#[1] TRUE
all.equal(shift(x, -1), shift(x, type="lead"))
#[1] TRUE

x=rnorm(5)
all.equal(shift(x, 1), shift(x, type="lag"))
#[1] TRUE
all.equal(shift(x, -1), shift(x, type="lead"))
#[1] "'is.NA' value mismatch: 1 in current 0 in target"
data.table(shift(x, -1), shift(x, type="lead"))
#            V1          V2
#1:  0.00000000 -0.72878503
#2: -1.99289559 -0.06749116
#3: -0.72878503 -0.35050513
#4: -0.06749116  0.84235129
#5: -0.35050513          NA

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions