s-news
[Top] [All Lists]

Re: Convert a Matrix of Indices to a Matrix of Values

To: "Paul H. Lasky" <phlasky@earthlink.net>, s-news@lists.biostat.wustl.edu
Subject: Re: Convert a Matrix of Indices to a Matrix of Values
From: "Liaw, Andy" <andy_liaw@merck.com>
Date: Thu, 27 Mar 2008 20:34:06 -0400
References: <29439109.1206629576214.JavaMail.root@elwamui-little.atl.sa.earthlink.net>
Thread-index: AciQGlzTkm26bf2NSWKBONka/stGsQAURFfJ
Thread-topic: [S] Convert a Matrix of Indices to a Matrix of Values
This is in R, but should be the same in S-PLUS:
 
> m <- matrix(sample(1:5, 20, replace=T), 5, 4)
> m
     [,1] [,2] [,3] [,4]
[1,]    3    4    2    2
[2,]    1    2    2    2
[3,]    1    4    2    5
[4,]    4    4    1    3
[5,]    5    1    1    2
> V <- v[m]
> dim(V) <- dim(m)
> V
     [,1] [,2] [,3] [,4]
[1,] "c"  "d"  "b"  "b"
[2,] "a"  "b"  "b"  "b"
[3,] "a"  "d"  "b"  "e"
[4,] "d"  "d"  "a"  "c"
[5,] "e"  "a"  "a"  "b"
Andy


From: s-news-owner@lists.biostat.wustl.edu on behalf of Paul H. Lasky
Sent: Thu 3/27/2008 10:52 AM
To: s-news@lists.biostat.wustl.edu
Subject: [S] Convert a Matrix of Indices to a Matrix of Values


 I have m vectors v with different lengths, and a n X m matrix of indices.
I wish to transform the index matrix to a matrix of values of v, with each column representing values of v.

  Can this transformation be accomplished without looping ? Using loops
the transformation is straightforward, awkward, and time consuming.

  Paul H. Lasky
  P & B Consulting
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news


------------------------------------------------------------------------------
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 - direct contact information for affiliates is 
available at http://www.merck.com/contact/contacts.html) 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.

------------------------------------------------------------------------------

<Prev in Thread] Current Thread [Next in Thread>