Skip to content

Sorting a data frame by specifying a vector

1 message · Bert Gunter

#
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: