例如,
vec <- c(4,4,4,3,3,3,5,4,5,4,3,3,56)
(pos <- ?????????)
Run Code Online (Sandbox Code Playgroud)
我要回报
1 4 7 13
Run Code Online (Sandbox Code Playgroud)
类似于@Pratik的方法
您可以match与unique
match(unique(vec), vec)
#[1] 1 4 7 13
Run Code Online (Sandbox Code Playgroud)