来源:https://blog.csdn.net/samwalt/article/details/84707346
1、直接测试
> a= c(1,3,8,5,6,7,5,2) ## 测试数据 > max_idx <- which.max(a) ## 返回最大值在a中的索引 > max_idx [1] 3 > min_idx <- which.min(a) ## 返回最小值在a中的索引 > min_idx [1] 1 > gt3 <- which(a > 3) ## 返回大于3的值在a中的索引 > gt3 [1] 3 4 5 6 7 > eq3 <- which(a==3) ## 返回等于3的索引 > eq3 [1] 2 > sift_idx <- which(10:1 %in% a) ## 返回10到1的值在a中的索引,例如第一个数字8在a中的索引为3 > sift_idx [1] 3 4 5 6 8 9 10