[18698] in s-news-athena

home help back first fref pref prev next nref lref last post

Re: [S] Sorting matrix elements, keeping track of original positions

daemon@ATHENA.MIT.EDU (John Wallace)
Wed Jul 21 19:30:12 1999

Date: Wed, 21 Jul 1999 16:26:32 -0700 (PDT)
From: John Wallace <jrw@fish.washington.edu>
To: Kim Elmore <elmore@nssl.noaa.gov>
Cc: S-News mail list <s-news@wubios.wustl.edu>
In-Reply-To: <Pine.GSO.4.10.9907211539420.4946-100000@ev.nssl.noaa.gov>
Message-Id: <Pine.SUN.3.96.990721162208.6194B-100000@pisces.fish.washington.edu>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII


On Wed, 21 Jul 1999, Kim Elmore wrote:

> > On second thought, perhaps you want
> > 
> >   positioner _ function(a){
> >  ro _ sapply(sort(a),function(x) row(a)[a==x])
> >  co _ sapply(sort(a),function(x) col(a)[a==x])
> >  cbind(ro,co)}
> > 

A one-liner (without column names) would be:

> a

     [,1] [,2] [,3] 
[1,]   27   24   29
[2,]   21   22   28
[3,]   23   26   25

> t(sapply(sort(a),function(x) c(row(a)[a==x], col(a)[a==x])))

     [,1] [,2] 
[1,]    2    1
[2,]    2    2
[3,]    3    1
[4,]    1    2
[5,]    3    3
[6,]    3    2
[7,]    1    1
[8,]    2    3
[9,]    1    3


-- 
John Wallace
University of Washington                    ^    ^    ^
Fisheries Research Institute               / \  / \  / \   ^
Box 357980                                 / \  / \   |   / \
Seattle, WA 98195-7980                      |    |  o__~  / \
PHONE   (206) 860-3456                  @ @         /\/\   |
FAX     (206) 860-3394                   ~    
E-MAIL        jw@u.washington.edu              o
WWW      http://www.fish.washington.edu/people/jrw/Wallace.html 
                                                o  _///_ //
                                                <`)=  _<<
                                                    \\\  \\

"For we are all prisoners of our times and days, yet all may
seek the freedom of heart that cannot be taken from us by any
power."
                     In:  _To See Heaven in a Wild Flower_
                               by Ann Tonsor Zeddies 

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

home help back first fref pref prev next nref lref last post