This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to select certain matrix rows

So I have two gene arrays, and I need to select the 15 top-varying genes from each and then plot the methylation data of both against each other. I am running into a problem - how do I actually create the matrix subset with only the 15 top varying genes?
I have been using:


normal <- cancerdata


variances <- matrixStats::rowVars(normal)


select <-order(variances, decreasing = T)[seq_len(min(15, length(variances)))]


normalmatrix <- as.matrix(METnormal[variances, ])


however, this does not create the "normalmatrix" matrix that I want which includes only the selected top-varying gene rows, but also all the sample columns. Does anyone have a solution? Any sample code would be appreciated.
For reference, I am using data sets such as those found here: http://gdac.broadinstitute.org/runs/stddata__2015_04_02/data/ACC/20150402/

rna-seq

If you just want the top 15 rows of your matrix by variance, you can simply do the following:

# create some fake test data
normal <- matrix(runif(1000), nrow=100,ncol=10)
# get the variance of each row
variances <- matrixStats::rowVars(normal)
# return the top 15 rows with the most variance
normalTop15 <- normal[order(variances, decreasing = T)[1:15],]

That's what your question appears to be asking for, but the code you have seems to be doing other things (i.e. where did METnormal come from?)

0 answers

No answers yet.

Log in to answer this question.