Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取R中向量中重复值的第一个元素的索引_R_Vector_Subset - Fatal编程技术网

获取R中向量中重复值的第一个元素的索引

获取R中向量中重复值的第一个元素的索引,r,vector,subset,R,Vector,Subset,我们如何才能在a中,获得重复值索引的第一个元素的索引,第一个1,第二个,第三个 一个选择是tapply 或使用 which(!duplicated(a)) 或者用什么和区别 或者当向量不是数字时 which(c(TRUE, a[-1] != a[-length(a)])) 一个选择是tapply 或使用 which(!duplicated(a)) 或者用什么和区别 或者当向量不是数字时 which(c(TRUE, a[-1] != a[-length(a)])) 另一个选择是匹配 来自帮

我们如何才能在a中,获得重复值索引的第一个元素的索引,第一个1,第二个,第三个

一个选择是tapply

或使用

which(!duplicated(a))
或者用什么和区别

或者当向量不是数字时

which(c(TRUE, a[-1] != a[-length(a)]))
一个选择是tapply

或使用

which(!duplicated(a))
或者用什么和区别

或者当向量不是数字时

which(c(TRUE, a[-1] != a[-length(a)]))
另一个选择是匹配

来自帮助“匹配”

match返回其第一个参数的第一个匹配项在第二个参数中的位置向量

另一个选择是匹配

来自帮助“匹配”

match返回其第一个参数的第一个匹配项在第二个参数中的位置向量

这里基本上回答了-也是sapplyuniquea,functionx which.maxx==a,但是已经有了更好的答案。这里基本上回答了-也是sapplyuniquea,functionx which.maxx==a,但是已经有了更好的答案。
which(c(TRUE, a[-1] != a[-length(a)]))
match(unique(a), a)
# [1] 1 4 6 7