[R] Rank Values in a Matrix

Marianne Promberger mpromber at psych.upenn.edu
Wed May 21 16:18:21 CEST 2008


On 05/19/08 13:46, Jens Oldeland wrote:
> Dear All,
>
> a short and maybe simple question:
>
>
> I have to rank all values in a matrix from 0 to X,
>
>    [1]   [2] [3]  [4]
> [1] 0.1  2   0    3
> [2] 50   3   3    1
> [3] 100 1   1    0
> [4] 100  2  2    0
>
> 0->0
> 0.1->1
> 2->2
> 3->3
> 50->4
> 100->5  (X=5)
>

Does this do what you want?

x <- matrix(c(3,100,0.1,3,100,2,5,0,0,50),5)
y <- as.data.frame(table(x))
y$Rank <- rank(y$x)

m.


-- 
Marianne Promberger
Graduate student in Psychology
http://www.psych.upenn.edu/~mpromber



More information about the R-help mailing list