[R] ordering by a datframe date

Gabor Grothendieck ggrothendieck at gmail.com
Sun Aug 6 07:37:21 CEST 2006


Try this:


Lines <- "story,datepub
story10,1 April 1999
story 90,1 March 2002
story 37,10 July 1985
"
DF <- read.csv(textConnection(Lines))

DF[order(as.Date(DF$datepub, "%d %B %Y")),]


On 8/6/06, Bob Green <bgreen at dyson.brisnet.org.au> wrote:
>
> I am hoping for some advice regarding ordering a dataframe, by date.
>
> The dataframe is in the format below.
>
> $story          $datepub
> story10      1 April 1999
> story 90    1 March 2002
> story 37    10 July 1985
>
>
> I want to reorder the entire dataframe so the earliest story is first, and
> save the reordered dataframe. The command, 'class' (datepub) reveals
> $datepub is a factor variable.
>
> I tried the following:
>
> d2 <- as.character(datepub)
> rank(d2)
>
> Any assistance is appreciated,
>
> regards
>
> Bob Green
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list