[R] ordered matrix question
Gavin Simpson
gavin.simpson at ucl.ac.uk
Tue Feb 27 19:09:25 CET 2007
On Tue, 2007-02-27 at 14:46 -0300, Juan Pablo Fededa wrote:
> Hi all,
>
> Is there an easy way to generate an object wich will be the same matrix, but
> ordered by de cfp value?
> The data frame consists of numeric columns:
> "Block" "X" "Y" "cfp" "yfp" "ID"
> 0 524 244 213.41795 7.18482109 1
> 0 556 270 65.383904 9.568372661 2
> 0 528 316 40.789474 5.573732175 3
> 0 642 432 135.81734 12.40134427 4
> 0 716 430 34.359135 3.944923077 5
> 0 894 362 109.63158 3.197160316 6
> 0 958 130 63.98452 3.396452004 7
> 0 506 92 83.513931 9.105496856 8
> 0 476 464 91.674919 9.178089414 9
> 0 364 426 44.13932 2.068334364 10
>
> Thanks in advance,
Yes, see ?order. E.g.:
mat <- scan()
0 524 244 213.41795 7.18482109 1
0 556 270 65.383904 9.568372661 2
0 528 316 40.789474 5.573732175 3
0 642 432 135.81734 12.40134427 4
0 716 430 34.359135 3.944923077 5
0 894 362 109.63158 3.197160316 6
0 958 130 63.98452 3.396452004 7
0 506 92 83.513931 9.105496856 8
0 476 464 91.674919 9.178089414 9
0 364 426 44.13932 2.068334364 10
mat <- data.frame(matrix(mat, ncol = 6, byrow = TRUE))
names(mat) <- c("Block", "X", "Y", "cfp", "yfp", "ID")
mat
mat[order(mat$cfp), ]
HTH
G
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson [t] +44 (0)20 7679 0522
ECRC, UCL Geography, [f] +44 (0)20 7679 0565
Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/
UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
More information about the R-help
mailing list