Skip to content
Back to formatted view

Raw Message

Message-ID: <3E91BF51.1080808@optonline.net>
Date: 2003-04-07T18:11:29Z
From: Chuck Cleland
Subject: How to sort a dataframe?
In-Reply-To: <IPOIHPHJJKHNFEAA@mailcity.com>

Remko Duursma wrote:
> for the purpose of plotting a dataframe, i am trying to sort a dataframe by one column, for example
> 
> tester <- data.frame(one=c(3,2,1), two=c(2,3,1))
> 
> #> tester
> #  one two
> #1   3   2
> #2   2   3
> #3   1   1
> 
> # I want to sort "tester" by column "one", so that i get a dataframe
> # that looks like:
> #one two
> #1    1
> #2    3
> #3    2

Remko:

   First examine the results of the following:

order(tester[,1])

   Then try this:

tester[order(tester[,1]),]

   See ?order.

hope it helps,

Chuck Cleland