Skip to content

Error using frankv with random ties method #5359

@rbutleriii

Description

@rbutleriii

When trying to use frankv to assign group based rankings, I got a confusing error. The issue seems to be only with the ties.method="random"

Example:

dt1 = data.table(id=c('11', '11', '11', '22', '22', '88', '99', '44', '44', '55'),
                 id2=c('11', '12', '12', '23', '23', '89', '90', '45', '45', '56'),
                 id3=c('11', '13', '13', '23', '23', '89', '91', '46', '46', '57'),
                 id4=c('11', '14', '14', '24', '24', '80', '92', '47', '47', '58'),
                 date = as.Date(c("01-01-2016", "01-02-2016", "01-02-2016", "02-01-2016",
                                  "02-02-2016"), format = "%m-%d-%Y"))
colz = c("id", "id4", "id3", "id2")
dt1[, rank := frankv(.SD, cols=colz, order=-1L, ties.method="first"), by="date"]
dt1[, rank := frankv(.SD, cols=colz, order=-1L, ties.method="last"), by="date"]
dt1[, rank := frankv(.SD, cols=colz, order=-1L, ties.method="average"), by="date"]
dt1[, rank := frankv(.SD, cols=colz, order=-1L, ties.method="max"), by="date"]
dt1[, rank := frankv(.SD, cols=colz, order=-1L, ties.method="min"), by="date"]
dt1[, rank := frankv(.SD, cols=colz, order=-1L, ties.method="dense"), by="date"]
dt1[, rank := frankv(.SD, cols=colz, order=-1L, ties.method="random"), by="date"]
# Error in set(x, idx, "..stats_runif..", stats::runif(n)) :
#   .SD is locked. Updating .SD by reference using := or set are reserved for future use. Use := in j directly. 
# Or use copy(.SD) as a (slow) last resort, until shallow() is exported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions