R语言which函数


# 新建数组
a=c(1,3,4,5,3,2,5,6,3,2,5,6,7,5,8)

# 取数组a中最大值的下标
which.max(a)

# 取数组a中最小值的下标
which.min(a)

# 取数组a中大于3值的下标
which(a>3)

# 取数组a中等于3值的下标
which(a==3)

# 10到1的数组元素中在a中的元素的下标
> b <- which(10:1 %in% a)
> b
[1] 3 4 5 6 7 8 9 10
发布了10 篇原创文章 · 获赞 0 · 访问量 308

# 新建数组
a=c(1,3,4,5,3,2,5,6,3,2,5,6,7,5,8)

# 取数组a中最大值的下标
which.max(a)

# 取数组a中最小值的下标
which.min(a)

# 取数组a中大于3值的下标
which(a>3)

# 取数组a中等于3值的下标
which(a==3)

# 10到1的数组元素中在a中的元素的下标
> b <- which(10:1 %in% a)
> b
[1] 3 4 5 6 7 8 9 10

猜你喜欢

转载自blog.csdn.net/weixin_44612629/article/details/104037505