On Fri, Mar 9, 2012 at 8:35 AM, carol white wrote:
> Hello,
> How is it possible to sort dates in R?
>
Your question has already been answered but note that if your data is
a time series and you represent it using zoo it will automatically be
sorted. Here dates is in reverse chronological order
How is it possible to sort dates in R?
Try this:
a = sample(as.Date(1:100, origin = '2012-01-01'),15)
a
[1] "2012-01-31" "2012-01-22" "2012-03-18" "2012-03-05" "2012-03-17"
[6] "2012-03-08" "2012-01-08" "2012-01-20" "2012-03-01" "2012-03-21"
[11] "2012-02-17" "2012-01-17" "2012-02-12" "2012-02
Hi
>
> Hello,
> How is it possible to sort dates in R?
You mean sort? Or order? Something like:
> dd <-sample(Sys.Date()-1:10)
> dd
[1] "2012-03-04" "2012-03-05" "2012-02-29" "2012-03-01" "2012-03-02"
[6] "2012-03-08" "2012-03-03" "2012-02-28" "2012-03-06" "2012-03-07"
> sort(dd)
[1] "2012-0
? sort
x <- c(Sys.Date(), Sys.Date() + 1, Sys.Date() - 1)
print(x)
print(sort(x))
Michael
On Fri, Mar 9, 2012 at 8:35 AM, carol white wrote:
> Hello,
> How is it possible to sort dates in R?
>
> Cheers,
>
> Carol
>
> __
> R-help@r-project.org mailin
t;] <- NA
Xavier
- Mail Original -
De: "Stefan Uhmann"
À: r-help@r-project.org
Envoyé: Mardi 29 Septembre 2009 13h15:10 GMT +01:00 Amsterdam / Berlin / Berne
/ Rome / Stockholm / Vienne
Objet: Re: [R] sort dates within a factor
Hi Xavier,
thank you for your suggestion, it'
On Tue, Sep 29, 2009 at 6:58 AM, wrote:
> Apologies for the misunderstanding. I can come up with a solution that might
> suit your needs:
>
> library(plyr)
> out <- ddply(test, .(nr), function(x) data.frame(date=x$date,
> index=rank(-as.integer(x$date
> out[is.na(out$nr) | is.na(out$date),
riginal -
De: "Stefan Uhmann"
À: r-help@r-project.org
Envoyé: Mardi 29 Septembre 2009 13h15:10 GMT +01:00 Amsterdam / Berlin / Berne
/ Rome / Stockholm / Vienne
Objet: Re: [R] sort dates within a factor
Hi Xavier,
thank you for your suggestion, it's not exactly what I need. Howe
Hi Xavier,
thank you for your suggestion, it's not exactly what I need. However I
made some progress using tapply, but it does not give me the 'correct'
result (see index - that's what I want to obtain!) when NAs are involved:
test <- data.frame(date =
as.Date(c('2007-01-01','2008-03-24','NA'
Is this what you want?
test[order(test$nr, -as.integer(test$date)),]
Xavier
- Mail Original -
De: "Stefan Uhmann"
À: r-help@r-project.org
Envoyé: Mardi 29 Septembre 2009 11h27:20 GMT +01:00 Amsterdam / Berlin / Berne
/ Rome / Stockholm / Vienne
Objet: [R] sort dates within a factor
De
9 matches
Mail list logo