Skip to content
Back to formatted view

Raw Message

Message-ID: <DovoiFAQo0e8Ew7t@myatt.demon.co.uk>
Date: 2002-02-26T08:40:48Z
From: Mark Myatt
Subject: another basic ?
In-Reply-To: <4.3.2.7.2.20020225120152.00a9d100@pop.service.ohio-state.edu>

jimi adams <adams.644 at osu.edu> writes:
>i am sure that there is a simple solution that i am just overlooking, but 
>there is no logical test for =
>there is one for != and >,<, >=, <=...
>what do i do if i need to check if something IS EQUAL

        == 

> or is there an easy way, in working with a matrix of size n x 3,  to sort 
> the matrix by one of the columns?

Use order() with the column (or row) indices:

        my.matrix[order(my.matrix[,column.to.sort.on]), ]

As in:

        > my.matrix <- matrix(c(5:1, 6:8, 12:9), nrow = 4)
        > my.matrix

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

        > my.sorted.matrix <- my.matrix[order(my.matrix[ ,1]), ]
        > my.sorted.matrix

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

Best wishes,

Mark

--
Mark Myatt


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._