-3

I need to pull the genes with the TRUE values out of each column of the matrix and form a list of them for each of my contrasts (columns). How do I go about doing that?

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

Here is the output:

[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
lmo
  • 37,904
  • 9
  • 56
  • 69
Alysha
  • 35
  • 1
  • 1
  • 11
  • If you look at the output of the print, some of the columns have TRUE in the rows. I want to pull out those rows for each column. – Alysha Dec 07 '16 at 17:37
  • In order for us to be able to answer your question, please include a sample of your data by typing `dput(gcQs2[1:10,1:6])` and copying and pasting the console output into your question. Also include the desired output for `gcQs2[1:10,1:6]` so we know if the solution matches what you want. For more information on how to make a reproducible example in `R` (and make it more likely your question is answered) please view [this post](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Barker Dec 07 '16 at 17:53
  • do you want to delete the whole row or column ? or what do you want to put instead ? – ClementWalter Dec 07 '16 at 17:57
  • `dput(gcQs2[1:10,1:6])` Output:`structure(c(FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE), .Dim = c(10L, 6L), .Dimnames = structure(list(c("1415670_at", "1415671_at", "1415672_at", "1415673_at", "1415674_a_at", "1415675_at", "1415676_a_at", "1415677_at", "1415678_at", "1415679_at"), Contrasts = c("KOInfvsKOUnInf", "WTInfvsWTUnInf", "KOInfvsWTInf", "KOInfvsWTUnInf", "KOUnInfvsWTInf", "KOUnInfvsWTUnInf")), .Names = c("", "Contrasts")))` – Alysha Dec 07 '16 at 17:57
  • I cut some FALSEs out of my comment above so it would fit. @clemlaflemme If I could delete the rows with only FALSE results, I'm sure that would help. – Alysha Dec 07 '16 at 17:59
  • try `mat <- mat[rowSums(mat)>0, ]` – ClementWalter Dec 07 '16 at 18:02
  • @clemlaflemme that deleted all of the rows that only had FALSE entries. Thanks! – Alysha Dec 07 '16 at 18:06

1 Answers1

0

I tried to figure out what you were saying and built this 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"
ClementWalter
  • 4,814
  • 1
  • 32
  • 54