Displaying 2 results from an estimated 2 matches for "is_unique".
Did you mean:
id_unique
2016 Mar 16
2
match and unique
Is the phrase "index <- match(x, sort(unique(x)))" reliable, in the sense that it will
never return NA?
Context: Calculation of survival curves involves the concept of unique death times. I've
had reported cases in the past where survfit failed, and it was due to the fact that two
"differ by machine precision" values would sometimes match and sometimes not,
2016 Mar 17
0
match and unique
...loating point values.
Unfortunately rank() is very slow, much slower than sort(). Here is a
faster solution based on sort.list(x, na.last=NA, method="quick"):
assignID <- function(x)
{
oo <- sort.list(x, na.last=NA, method="quick")
sorted <- x[oo]
is_unique <- c(TRUE, sorted[-length(sorted)] != sorted[-1L])
sorted_ID <- cumsum(is_unique)
ID <- integer(length(x))
ID[oo] <- sorted_ID
ID
}
'assignID(x)' is also slightly faster than 'match(x, sort(unique(x)))':
x <- runif(5000000)
system.time(i...