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 03
> [2] 50 3 31
> [3] 100 1 10
> [4] 100 2 20
>
> 0->0
> 0.1->1
> 2->2
> 3->3
> 50->4
M
> To: Jens Oldeland; [EMAIL PROTECTED]
> Subject: Re: [R] Rank Values in a Matrix
>
> If your matrix below is called aa, you could do this
>
> > matrix(rank(aa, ties='min'), ncol=ncol(aa))
> [,1] [,2] [,3] [,4]
> [1,]481 11
> [2,] 14
Hi Jens,
If the matrix you described is m.
Then, you can do
> unique(as.vector(m))
[1] 0.1 2.0 0.0 3.0 50.0 1.0 100.0
> order(unique(as.vector(m)))
[1] 3 1 6 2 4 5 7
Hope this helps :)
Naira
Jens Oldeland wrote:
Dear All,
a short and maybe simple question:
I have to rank all va
If your matrix below is called aa, you could do this
> matrix(rank(aa, ties='min'), ncol=ncol(aa))
[,1] [,2] [,3] [,4]
[1,]481 11
[2,] 14 11 115
[3,] 15551
[4,] 15881
This doesn't assign the values you list, but it does rank them. OTOH, if
4 matches
Mail list logo