Examples for 'data.table::frank'


Fast rank

Aliases: frank frankv rank

Keywords: data

### ** Examples

# on vectors
x = c(4, 1, 4, NA, 1, NA, 4)
# NAs are considered identical (unlike base R)
# default is average
frankv(x) # na.last=TRUE
[1] 4.0 1.5 4.0 6.5 1.5 6.5 4.0
frankv(x, na.last=FALSE)
[1] 6.0 3.5 6.0 1.5 3.5 1.5 6.0
# ties.method = min
frankv(x, ties.method="min")
[1] 3 1 3 6 1 6 3
# ties.method = dense
frankv(x, ties.method="dense")
[1] 2 1 2 3 1 3 2
# on data.table
DT = data.table(x, y=c(1, 1, 1, 0, NA, 0, 2))
frankv(DT, cols="x") # same as frankv(x) from before
[1] 4.0 1.5 4.0 6.5 1.5 6.5 4.0
frankv(DT, cols="x", na.last="keep")
[1] 4.0 1.5 4.0  NA 1.5  NA 4.0
frankv(DT, cols="x", ties.method="dense", na.last=NA)
[1] 2 1 2 1 2
frank(DT, x, ties.method="dense", na.last=NA) # equivalent of above using frank
[1] 2 1 2 1 2
# on both columns
frankv(DT, ties.method="first", na.last="keep")
[1]  2  1  3 NA NA NA  4
frank(DT, ties.method="first", na.last="keep") # equivalent of above using frank
[1]  2  1  3 NA NA NA  4
# order argument
frank(DT, x, -y, ties.method="first")
[1] 4 1 5 6 2 7 3
# equivalent of above using frankv
frankv(DT, order=c(1L, -1L), ties.method="first")
[1] 4 1 5 6 2 7 3

[Package data.table version 1.14.2 Index]