【发布时间】:2020-03-15 12:56:07
【问题描述】:
如何在a中,获取第一个元素的重复值的索引(第一个1的索引,第一个2,第一个3...)?
a <- c(rep(1, 3), rep(2, 2), rep(3, 1), rep(4, 2))
desired.output <- c(1, 4, 6, 7)
【问题讨论】:
-
这里基本上回答了 - stackoverflow.com/questions/5577727/…
-
还有
sapply(unique(a), function(x) which.max(x == a)),但已经有了更好的答案。