s-news
[Top] [All Lists]

[S] Q on arranging in the descending order

To: s-news@wubios.wustl.edu
Subject: [S] Q on arranging in the descending order
From: Mikio Kaihara <mkaihara@ichinoseki.ac.jp>
Date: Thu, 25 Jun 1998 12:14:47 +0900
Sender: owner-s-news@wubios.wustl.edu
Dear sir,

  I(Win 95, S-PLUS ver4.0, beginner) made the program(mk5) which arranged size 
of the value of procession uu and procession ab corresponding to it in the 
descending order. 
(Matrix, uu[i,1] were calculated by corresponding matrix, ab[,,i].)
  However, it does not operate as thought. I suppose the use of the condition 
sentence could be wrong.  Would you please help me?
-------------------------------------------------
> uu
          [,1] 
[1,]  15900.76
[2,] 987321.96
[3,] 554920.90
[4,] 246247.97
[5,]  61303.16
> ab

, , 1
     [,1] [,2] 
[1,]   -3   -1
[2,]   -2    0

, , 2
     [,1] [,2] 
[1,]   13   15
[2,]   14   16

, , 3
     [,1] [,2] 
[1,]    9   11
[2,]   10   12

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

, , 5
     [,1] [,2] 
[1,]    1    3
[2,]    2    4
> mk5
function()
{
        work <- 0
        twork <- 0      #browser()
        for(i in 1:4) {
                i1 <- i + 1
                for(j in i1:5) {
                        if(uu[i, 1] < uu[j, 1])
                                work <- uu[i, 1]
                        twork <- ab[,  , i]
                        uu[i, 1] <<- uu[j, 1]
                        ab[,  , i] <<- ab[,  , j]
                        uu[j, 1] <<- work
                        ab[,  , j] <<- twork
                }
        }
}
> mk5()
> uu
         [,1] 
[1,] 61303.16
[2,] 15900.76
[3,] 15900.76
[4,] 15900.76
[5,] 15900.76
> ab

, , 1
     [,1] [,2] 
[1,]    1    3
[2,]    2    4

, , 2
     [,1] [,2] 
[1,]    5    7
[2,]    6    8

, , 3
     [,1] [,2] 
[1,]    9   11
[2,]   10   12

, , 4
     [,1] [,2] 
[1,]   13   15
[2,]   14   16

, , 5
     [,1] [,2] 
[1,]   -3   -1
[2,]   -2    0
>

------------------------------
Mikio 
mkaihara@ichinoseki.ac.jp  
Tel:+81-191-24-4772、; 
Fax:+81-191-24-2146
INCT, 021-8511, Japan
------------------------------
-----------------------------------------------------------------------
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

<Prev in Thread] Current Thread [Next in Thread>
  • [S] Q on arranging in the descending order, Mikio Kaihara <=