s-news
[Top] [All Lists]

Re: General-purpose function for sorting data frame

To: Jean V Adams <jvadams@usgs.gov>
Subject: Re: General-purpose function for sorting data frame
From: Douglas Bates <bates@stat.wisc.edu>
Date: Wed, 29 Sep 2004 10:04:04 -0500
Cc: kwright@eskimo.com, s-news@lists.biostat.wustl.edu, Thom.Burnett@cognigencorp.com
In-reply-to: <OF0B65E467.A728D85A-ON85256F1E.004FC4F3@er.usgs.gov>
Organization: University of Wisconsin - Madison
References: <OF0B65E467.A728D85A-ON85256F1E.004FC4F3@er.usgs.gov>
Reply-to: bates@wisc.edu
User-agent: Mozilla Thunderbird 0.8 (X11/20040918)
Jean V Adams wrote:
Isn't using rev() a more convenient approach?

In your example:
Oats[order(rev(Oats$nitro), Oats$Variety), ]

For Thom Burnett's recently posted example:
attach(unsortedData)
sortedData <- unsortedData[order(sex, rev(race), rev(smoking), weight), ]
detach("unsortedData")

JVA

I haven't tried it but it doesn't seem like that will work because rev() just reverses the order of the elements in the vector. I think that

order(sex, rev(race), rev(smoking), weight)

will be exactly the same as

order(sex, race, smoking, weight)



<Prev in Thread] Current Thread [Next in Thread>