s-news
[Top] [All Lists]

Re: Exchanging Indices of a Matrix

To: <s-news@lists.biostat.wustl.edu>
Subject: Re: Exchanging Indices of a Matrix
From: "Quinn, David" <David.Quinn@nrgenergy.com>
Date: Tue, 25 Jun 2002 12:54:06 -0500
Thread-index: AcIcbO+6Gk3JGvv3RMGKsN2lyuVFgAAA/aPw
Thread-topic: Exchanging Indices of a Matrix
Thanks for the answers.  All I am doing below is transposing t().  (somehow 
this didn't occur to me.)  But in general I could use permutation aperm().  As 
Win Lambert and Brian Ripley points out, these functions loop internally but 
they loop in C so it's much faster.

David

 -----Original Message-----
From:   Quinn, David  
Sent:   Tuesday, June 25, 2002 12:23 PM
To:     s-news@lists.biostat.wustl.edu
Cc:     Quinn, David
Subject:        [S] Exchanging Indices of a Matrix

Is there an easy way to do the following without the looping?  I'm guessing 
not, since I think the internal representation of a matrix is as a list.    -- 
Thanks, David

for (i in 1:x)
{
        for (j in 1:y)
        {
                for (k in 1:z)
                {
                        new.matrix[k,j,i] <- old.matrix[i,j,k]
                }
        }
}

--------------------------------------------------------------------
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



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