[R] Sorting elements in a data.frame

Patrick Connolly p.connolly at hortresearch.co.nz
Wed Jun 30 01:40:37 CEST 2004


On Wed, 23-Jun-2004 at 07:29PM +0100, Dan Bolser wrote:

|> 
|> Hi,
|> 
|> I have data like this....
|> 
|> print(x)
|> 
|> ID	VAL1	VAL2
|> 1	2	6
|> 2	4	9
|> 3	45	12
|> 4	99	44
|> 
|> What I would like is data like this...
|> 
|> ID	VAL1	VAL2
|> 1	2	6
|> 2	4	9
|> 3	12	45
|> 4	44	99
|> 
|> 
|> So that my analysis of the ratio VAL2/VAL1 is somehow uniform.

By "uniform", I'm guessing you want them to be >= 1

If z is a vector of VAL2/VAL1 values, you can make them all >= 1 this way.

z[z < 1] <- z[z < 1]^-1

Depending on just how you want to use them, there could be better ways
but I've done enough guessing for now.

HTH

-- 
Patrick Connolly
HortResearch
Mt Albert
Auckland
New Zealand 
Ph: +64-9 815 4200 x 7188
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
I have the world`s largest collection of seashells. I keep it on all
the beaches of the world ... Perhaps you`ve seen it.  ---Steven Wright 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~




More information about the R-help mailing list