[BioC] conditional selection: extracting row from matrix

John Zhang jzhang at jimmy.harvard.edu
Tue Jan 6 18:41:50 MET 2004


>I have an (n,m) matrix with rownames and colnames. The rownames are probe set 
ids. I know a value of one of the probe sets which is, say, in column 2 of the 
matrix. I would like to retrieve the rowname, or probe set id, of the row which 
contains this value.
>
>Neither of these work:
>
>matrix[,matrix[,2]==513.193057]
>(Error: (subscript) logical subscript too long)

Try this:

> tt <- matrix(1:20, ncol = 4)
> tt
     [,1] [,2] [,3] [,4]
[1,]    1    6   11   16
[2,]    2    7   12   17
[3,]    3    8   13   18
[4,]    4    9   14   19
[5,]    5   10   15   20
> tt[tt[,2] == 8, ]
[1]  3  8 13 18



>
>index <- which(matrix[,2] == 513.193057)
>matrix[index,]
>
>Of course, I could write.table() the matrix and search the file. But I would 
like to know how this is done in R/Bioconductor.
>
>Thank you very much.
>
>Juerg Straubhaar,
>Umass Med
>
>_______________________________________________
>Bioconductor mailing list
>Bioconductor at stat.math.ethz.ch
>https://www.stat.math.ethz.ch/mailman/listinfo/bioconductor

Jianhua Zhang
Department of Biostatistics
Dana-Farber Cancer Institute
44 Binney Street
Boston, MA 02115-6084



More information about the Bioconductor mailing list