From: Wolfram Fischer <wolfram_at_fischer-zim.ch>

Date: Fri 09 Jul 2004 - 00:26:00 EST

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 Fri Jul 09 00:37:28 2004

Date: Fri 09 Jul 2004 - 00:26:00 EST

Thanks for you answer! It works.

*> m <- outer(letters[1:5], 1:4, paste, sep="")
*

Do you have another suggestion? - Thanks! Wolfram

- In reply to: ---

*>Date: 08.07.04 08:21 (-0400)**>From: "Liaw, Andy" <andy_liaw@merck.com>**>Subject: RE: [R] Getting elements of a matrix by a vector of column indice s**>*

> See if the following helps:

*>**> > m <- outer(letters[1:5], 1:4, paste, sep="")**> > m**> [,1] [,2] [,3] [,4]**> [1,] "a1" "a2" "a3" "a4"**> [2,] "b1" "b2" "b3" "b4"**> [3,] "c1" "c2" "c3" "c4"**> [4,] "d1" "d2" "d3" "d4"**> [5,] "e1" "e2" "e3" "e4"**> > idx <- c(2, 1, 3, 4, 2)**> > m[cbind(1:5, idx)]**> [1] "a2" "b1" "c3" "d4" "e2"**>**> Andy**>**> > From: Wolfram Fischer**> >**> > 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**> >**> >**>**>**> ------------------------------------------------------------------------------**> Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as Banyu) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system.**> ------------------------------------------------------------------------------*

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 Fri Jul 09 00:37:28 2004

*
This archive was generated by hypermail 2.1.8
: Wed 03 Nov 2004 - 22:54:47 EST
*