[R] Getting elements of a matrix by a vector of column indices

From: Wolfram Fischer <wolfram_at_fischer-zim.ch>
Date: Thu 08 Jul 2004 - 19:58:02 EST


I have e.g.

    t <- matrix( nrow=2, ncol=3, byrow=TRUE, c('a1','a2','a3','b1','b2','b3') ) and

    i <- c( 3, 2)

Is it possible to formulate a simple expression that gets

    c( t[ 1, i[1] ], t[ 2, i[2] ] )
(and so on for longer matrices)?

The result would be:

    [1] "a3" "b2"

Thanks - Wolfram



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jul 08 20:07:55 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 02:35:09 EST