找回密码
 注册
查看: 5615|回复: 2

获取向量 数组中元素对应的索引号或者下标号

[复制链接]
发表于 2010-6-28 10:11:52 | 显示全部楼层 |阅读模式
本帖最后由 genechip 于 2010-6-28 10:15 编辑

获取下标号的函数是which()
which(x, arr.ind = FALSE)Arguments
xa logical vector or array. NAs are allowed and omitted (treated as if FALSE)
arr.indlogical; should array indices be returned when x is an array?




Exampleswhich(LETTERS == "R")
which(ll <- c(TRUE,FALSE,TRUE,NA,FALSE,FALSE,TRUE))#> 1 3 7
names(ll) <- letters[seq(ll)]
which(ll)which((1:12)%%2 == 0) # which are even?
which(1:10 > 3, arr.ind=TRUE)
( m <- matrix(1:12,3,4) )
which(m %% 3 == 0)
which(m %% 3 == 0, arr.ind=TRUE)
rownames(m) <- paste("Case",1:3, sep="_")
which(m %% 5 == 0, arr.ind=TRUE)
dim(m) <- c(2,2,3); m
which(m %% 3 == 0, arr.ind=FALSE)
which(m %% 3 == 0, arr.ind=TRUE)
vm <- c(m)
dim(vm) <- length(vm) #-- funny thing with  length(dim(...)) == 1
which(vm %% 3 == 0, arr.ind=TRUE)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2024-11-21 21:50 , Processed in 0.028780 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表