-
Notifications
You must be signed in to change notification settings - Fork 991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement 'rank' #760
Comments
Hm, this is almost done. However, there's something I hadn't anticipated - x = c(0,1,NA,1,0,NA)
rank(x, ties="average")
# [1] 1.5 3.5 5.0 3.5 1.5 6.0 However, frankv(x, ties="average")
# [1] 1.5 3.5 5.5 3.5 1.5 5.5 It takes the average of This can of course be corrected by checking if But it does make extending Maybe it's necessary to first implement an efficient |
But the set.seed(45L)
x = sample(1e4, 1e7, TRUE)
system.time(ans1 <- rank(x))
# user system elapsed
# 18.106 0.165 19.460
system.time(ans2 <- frankv(x))
# user system elapsed
# 0.539 0.001 0.545
identical(ans1, ans2) # [1] TRUE
system.time(ans1 <- rank(x, ties="first"))
# user system elapsed
# 23.124 0.252 23.584
system.time(ans2 <- frankv(x, ties="first"))
# user system elapsed
# 0.719 0.002 0.725
identical(ans1, ans2) # [1] TRUE A common usage would be to use set.seed(45L)
x = sample(1e2, 1e4, TRUE)
system.time(for (i in 1:1e3) rank(x))
# user system elapsed
# 2.911 0.305 3.294
system.time(for (i in 1:1e3) frankv(x))
# user system elapsed
# 0.279 0.084 0.364
identical(rank(x), frankv(x)) # [1] TRUE |
Implemented fast rank of all types. DT[, rank(.SD, na.last=TRUE, ties="max") < 4L, by=...]
TODO:
DT[, rank(.SD, by=<cols>, ties="min", na.last=NA), by=...] for example. Even though it's possible to use
|
This is really straightforward from
forder
. Ranking types (frombase::rank
):plus extra...
runlength- will have to provide this as another function, not really ranking method.na.last =
order
Note that this will/should work on
list
input as well. Not just vectors likebase
.Here is an Q from SO that could greatly benefit from this.
The text was updated successfully, but these errors were encountered: