Re: [R] ordered matrix question

2007-02-27 Thread Daniel Nordlund
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> On Behalf Of Juan Pablo Fededa
> Sent: Tuesday, February 27, 2007 9:47 AM
> To: R-help@stat.math.ethz.ch
> Subject: [R] ordered matrix question
> 
> 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"
> 0524244213.417957.184821091
> 055627065.3839049.5683726612
> 052831640.7894745.5737321753
> 0642432135.8173412.401344274
> 071643034.3591353.9449230775
> 0894362109.631583.1971603166
> 095813063.984523.3964520047
> 05069283.5139319.1054968568
> 047646491.6749199.1780894149
> 036442644.139322.06833436410
> 
> Thanks in advance,
> 
> 
> Juan Pablo

Juan,

Look at ?order.  Something like this should work

your.df[order(your.df$cfp, decreasing=TRUE), ]

Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA  USA

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] ordered matrix question

2007-02-27 Thread Gavin Simpson
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"
> 0524244213.417957.184821091
> 055627065.3839049.5683726612
> 052831640.7894745.5737321753
> 0642432135.8173412.401344274
> 071643034.3591353.9449230775
> 0894362109.631583.1971603166
> 095813063.984523.3964520047
> 05069283.5139319.1054968568
> 047646491.6749199.1780894149
> 036442644.139322.06833436410
> 
> Thanks in advance,

Yes, see ?order. E.g.:

mat <- scan()
0524244213.417957.184821091
055627065.3839049.5683726612
052831640.7894745.5737321753
0642432135.8173412.401344274
071643034.3591353.9449230775
0894362109.631583.1971603166
095813063.984523.3964520047
05069283.5139319.1054968568
047646491.6749199.1780894149
036442644.139322.06833436410


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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] ordered matrix question

2007-02-27 Thread Earl F. Glynn
"Juan Pablo Fededa" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi all,
>
> Is there an easy way to generate an object wich will be the same matrix, 
> but
> ordered by de cfp value?

Does this help?

> RawData <- "BlockXYcfpyfpID
+ 0524244213.417957.184821091
+ 055627065.3839049.5683726612
+ 052831640.7894745.5737321753
+ 0642432135.8173412.401344274
+ 071643034.3591353.9449230775
+ 0894362109.631583.1971603166
+ 095813063.984523.3964520047
+ 05069283.5139319.1054968568
+ 047646491.6749199.1780894149
+ 036442644.139322.06833436410"
> d <- read.table(textConnection(RawData), header=TRUE)

> d.ordered <- data.matrix( d[order(d$cfp),] )

> d.ordered
   Block   X   Y   cfp   yfp ID
5  0 716 430  34.35914  3.944923  5
3  0 528 316  40.78947  5.573732  3
10 0 364 426  44.13932  2.068334 10
7  0 958 130  63.98452  3.396452  7
2  0 556 270  65.38390  9.568373  2
8  0 506  92  83.51393  9.105497  8
9  0 476 464  91.67492  9.178089  9
6  0 894 362 109.63158  3.197160  6
4  0 642 432 135.81734 12.401344  4
1  0 524 244 213.41795  7.184821  1


efg

Earl F. Glynn
Stowers Institute for Medical Research

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] ordered matrix question

2007-02-27 Thread Mendiburu, Felipe \(CIP\)
Juan Pablo,

X is data.frame or matrix
X <- X[order(X[,4]),]
options see help(order)

Felipe de Mendiburu

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Juan Pablo Fededa
Sent: Tuesday, February 27, 2007 12:47 PM
To: R-help@stat.math.ethz.ch
Subject: [R] ordered matrix question


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"
0524244213.417957.184821091
055627065.3839049.5683726612
052831640.7894745.5737321753
0642432135.8173412.401344274
071643034.3591353.9449230775
0894362109.631583.1971603166
095813063.984523.3964520047
05069283.5139319.1054968568
047646491.6749199.1780894149
036442644.139322.06833436410

Thanks in advance,


Juan Pablo

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] ordered matrix question

2007-02-27 Thread Juan Pablo Fededa
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"
0524244213.417957.184821091
055627065.3839049.5683726612
052831640.7894745.5737321753
0642432135.8173412.401344274
071643034.3591353.9449230775
0894362109.631583.1971603166
095813063.984523.3964520047
05069283.5139319.1054968568
047646491.6749199.1780894149
036442644.139322.06833436410

Thanks in advance,


Juan Pablo

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.