Java Mailing List Archive

http://www.r-help.com/

Home » R Help for Statistical Computing »

[R] how to get row name of matrix when result is a vector

mentor_

2010-09-03

Replies: Find Java Web Hosting

Author LoginPost Reply

Hi,

the R code:

a <- matrix(c(1,5,4,3,7,10,34,4,3,8,6,5,12,17,45,3,2,45,46,47,3,4,22,12,21),
nrow=5)
rownames(a) <- c("a","b","c","d","e")
a
a[which(a[,3] < 8), ]
a[which(a[,3] < 6), ]


produces the following output:

> a
[,1] [,2] [,3] [,4] [,5]
a   1  10   6   3   3
b   5  34   5   2   4
c   4   4  12  45  22
d   3   3  17  46  12
e   7   8  45  47  21

> a[which(a[,3] < 8), ]
[,1] [,2] [,3] [,4] [,5]
a   1  10   6   3   3
b   5  34   5   2   4

> a[which(a[,3] < 6), ]
[1] 5 34 5 2 4


I actually thought it must be rather easy to somehow extract the row name
when the result is just a vector as in the second example and not a matrix.
I tried several ways but without any success.

Any advice?
Best,
syrvn


--
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@(protected)
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.
©2008 r-help.com - Jax Systems, LLC, U.S.A.