[R] selecting matrix cels by two factors

From: Dimitri Joe <dimitrijoe_at_gmail.com>
Date: Sat 17 Dec 2005 - 10:02:24 EST


Hi,

I have a (numeric) matrix X of the type

> X <- matrix(c(1:9),ncol=3,nrow=3)
> colnames(X) <- c("A","B","C")
> rownames(X) <- c("D","E","F")

Also, a have a data frame Y like

> Y <- as.data.frame(cbind( c("D","E","F","D","E","F"),
+ c("A","C","A","B","B","C") ) )

I want a matrix like

1 4 X["D","A"] X["D","B"]
8 5 or, equivalentely, X["E","C"] X["E","B"] 3 9 X["F","A"] X["F","C"]

Any suggestions?
Thanks in advanced,

Dimitri



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Dec 17 10:09:10 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:39 EST