Dear list,

I would like to subset a large expression matrix based on rownames.

That is, I have a list (as a txt-file) with gene names that matches
some of the rows in my matrix.

I've loaded my matrix as well as gene list using the read.table() command.
myMatrix <- read.table("name_of_file.txt", header=T, row.names=1)
list_to_keep <- read.table("name_of_file.txt", header=T)

Thus, both my objects are data frames (however, "list_to_keep" only
have one column).

How do I remove/filter all the rows in my matrix that don't match the
ones in my list_to_keep data frame?

My initial attempt - although unsuccessful:
index <- list_to_keep[,1] %in% row.names(myMatrix)
subset.data <- myMatrix[index, ]

Alternatively, I could imagine that the subset() command would be
ideal, however I cannot write a functional script with this command.

Many thanks,
Peter

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to