Displaying 2 results from an estimated 2 matches for "assignid".
Did you mean:
assigned
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
...9;match(x, sort(unique(x))' but doesn't rely
on the assumption that match() and unique() agree on equality between
2 floating 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
}
'...