I'm trying to identify duplicates in an integer64 vector using the fromLast
argument in the duplicated()
function (my rows are ordered in time and I want to discard the earlier time points, keeping the most recent unique value). It doesn't seem to work.
It works for regular integer vectors:
> x <- c(1, 2, 3, 3, 4)
> base::duplicated(x)
[1] FALSE FALSE FALSE TRUE FALSE
> base::duplicated(x, fromLast = TRUE)
[1] FALSE FALSE TRUE FALSE FALSE
This is the correct behavior.
But it doesn't work on an integer64 vector:
> x <- as.integer64(c(1, 2, 3, 3, 4))
> base::duplicated(x)
[1] FALSE FALSE FALSE TRUE FALSE
> base::duplicated(x, fromLast = TRUE)
[1] FALSE FALSE FALSE TRUE FALSE
Any ideas?
The duplicated.integer64()
function doesn't have a fromLast
argument.
I can do rev(duplicated(rev(x)))
, but according to base R's documentation this is slower than using fromLast=TRUE
.
The problem is in the method dispatched. It is calling the duplicated.integer64
. If we want the same behaviour, use duplicated.default
duplicated.default(x, fromLast = TRUE)
#[1] FALSE FALSE TRUE FALSE FALSE
By checking the duplicated.integer64
, it doesn't have the fromLast
argument
> duplicated.integer64
function (x, incomparables = FALSE, nunique = NULL, method = NULL,
...)
where as there is an argument for fromLast
in duplicated.default
> duplicated.default
function (x, incomparables = FALSE, fromLast = FALSE, nmax = NA,
...)
library(bit64)
x <- as.integer64(c(1, 2, 3, 3, 4))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.