Matrix subsetting with rownames

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Matrix subsetting with rownames

Muppy
Hi,
I have a large matrix containing 10000 rows and 60 columns. I would like to subset this matrix by using a list of several hundred row names. I tried to find how to do that, eg with %in% or subset commands, but I never succeed and I do not find the proper method on internet. How to proceed ?
Thanks
Muppy
Reply | Threaded
Open this post in threaded view
|

Re: Matrix subsetting with rownames

Richard M. Heiberger
> tmp <- matrix(1:24, 6, 4, dimnames=list(letters[1:6], LETTERS[1:4]))
> tmp
  A  B  C  D
a 1  7 13 19
b 2  8 14 20
c 3  9 15 21
d 4 10 16 22
e 5 11 17 23
f 6 12 18 24
> tmp[c("a", "c", "d", "f"), ]
  A  B  C  D
a 1  7 13 19
c 3  9 15 21
d 4 10 16 22
f 6 12 18 24
>


See
   ?`[`
for discussion.

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: Matrix subsetting with rownames

Muppy
Hi,
this is what I want to do and what I found prior to ask there, but I wanted to do that with a vector of several hundreds or thounsands of names. Because I will have to use different vectors of very big size, my main concern was how to import this vector from a textfile (so I just have to change the name of the file in my script each time), but I finally found the correct command (scan) and it works.
Thanks