> my_matrix[rows, ]
Error in xj[i] : invalid subscript type 'list'
>
In my_matrix row.names are my genes :(
Hi,
I have a matrix in R, columns are my samples and rows my genes; I want to extract some genes by their position in rowslike genes 100, 876, 438, and 997 other genes.
I read these number as a vector but I don't know how to intersect as rownames of my matrix is genes rather the number
How I can do that please?
Thanks
if you have
rows <- c(100, 876, 438, ... 997 other entries ...)
then my_matrix[rows, ] is how you 'submatrix-by-row-index'. In R you can index by either rownames or indices, or a boolean 'mask' vector (here it would be a vector of FALSEs with TRUE at the 100th, 438th, 876th and the other 997 entries).
> my_matrix[rows, ]
Error in xj[i] : invalid subscript type 'list'
>
In my_matrix row.names are my genes :(
If you have the indices, you don't need rownames:
selected = genes[ c( 100, 876, 438, 997 ), ]
Log in to answer this question.
Hi jivarajivaraj,
This is a pretty basic R question. It actually doesn't belong on biostars, as we focus on bioinformatics and this is pure programming. I'm pretty sure that most R tutorials cover indexing of matrices, so I'd suggest you follow a tutorial (or a few). That would definitely pay off in the long run. Getting some programming skills is highly beneficial for the rest of your work.
Cheers,
Wouter
Hello jivarajivaraj!
We believe that this post does not fit the main topic of this site.
This is a basic R question, see:
For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.
If you disagree please tell us why in a reply below, we'll be happy to talk about it.
Cheers!