如何从矩阵中提取TRUE值

时间:2016-12-07 17:30:13

标签: r matrix

我需要从矩阵的每一列中提取具有TRUE值的基因,并为每个对比(列)形成它们的列表。我该怎么做呢?

gcQVals=qvalue(eBgcData$p.value)
print(sum(gcQVals$qvalues<=0.01))
gcQs2=gcQVals$qvalues<=0.01
print(gcQs2[1:5,1:6])

这是输出:

[1] 17969
              Contrasts
           KOInfvsKOUnInf WTInfvsWTUnInf KOInfvsWTInf KOInfvsWTUnInf
  1415670_at            FALSE          FALSE        FALSE          FALSE
  1415671_at            FALSE          FALSE        FALSE          FALSE
  1415672_at             TRUE          FALSE        FALSE           TRUE
  1415673_at            FALSE          FALSE        FALSE          FALSE
  1415674_a_at          FALSE          FALSE        FALSE          FALSE
          Contrasts
           KOUnInfvsWTInf KOUnInfvsWTUnInf
  1415670_at            FALSE            FALSE
  1415671_at            FALSE            FALSE
  1415672_at            FALSE            FALSE
  1415673_at            FALSE            FALSE
  1415674_a_at          FALSE            FALSE

1 个答案:

答案 0 :(得分:0)

我试图找出你在说什么并建立了这个MWE:

# build the example
a <- matrix(runif(9), 3, 3)>0.5
dimnames(a) <- list(letters[1:3], LETTERS[1:3])

# solution to your supposed problem
lapply(colnames(a), function(name) rownames(a)[a[,name]])

> a
      A     B     C
a FALSE  TRUE FALSE
b FALSE FALSE  TRUE
c FALSE FALSE FALSE

res <- lapply(colnames(a), function(name) rownames(a)[a[,name]])
names(res) <- colnames(a)
> res
$A
character(0)

$B
[1] "a"

$C
[1] "b"