0

I have a large data set in the form of a matrix, each row has its own unique name. I have a list of row names where I want to keep that data in that row. Is there a way that I can keep only the rows of my matrix that have row names in common with my list of row names? i.e. Can I throw out any row that does not have a row name in my list and be left with a matrix of the rows with names from my list?

Any help would be greatly appreciated! My current method is slow and very circuitous.

user10039910
  • 135
  • 4
  • 1
    possible duplicate of [Subsetting matrices](http://stackoverflow.com/questions/10133360/subsetting-matrices) Welcome to SO. Please read about [how to make a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) – Rich Scriven Jun 20 '14 at 19:55

1 Answers1

0

if dat is your data frame and names.to.keep is a vector containing the names of the rows which you want, then dat.keep = dat[rownames(dat) %in% names.to.keep, ]

should do what you want.

jld
  • 466
  • 10
  • 20