Skip to content
Prev 307687 / 398503 Next

Sorting a data frame by specifying a vector

On Thu, Oct 11, 2012 at 10:43 AM, ROLL Josh F <JRoll at lcog.org> wrote:
Actually, my bad -- I didn't read carefully enough.

But the answer is still essentially correct -- just change the
ordering of the levels of Season, which, by default, is alphabetic.

df$Season <- factor(df$Season, lev = c("Summer","Fall","Winter","Spring"))

df <- df[order(df$Season),]

Learn about factors (Read the Intro to R tutorial if you haven't
already). They are very handy (and much despised by some).

-- Bert


The result I am looking for would be something like:

  
    
Message-ID: <CACk-te37WLeo3aRk043=o0R9=xWpasXE4v8XJ9W-n4KW9u8RhA@mail.gmail.com>
In-Reply-To: <506F591A54F21D4480EE337F77369C050AC6A0BAB8@LCEXG03.lc100.net>