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
Hello,
How is it possible to sort dates in R?
Cheers,
Carol
__
R-help@r-project.org 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, s
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
]
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
Dear List,
I have the following data:
>>
test <- da
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 withi
Dear List,
I have the following data:
>>
test <- data.frame(date =
as.Date(c('2007-01-01','2008-03-24','2003-03-02','2008-05-03','2002-05-23','2001-06-30','2005-12-04')),
nr = c(2000,2000,2000,2001,2002,2003,2003))
test
date nr
1 2007-01-01 2000
2 2008-03-24 2000
3 2003-03-02
11 matches
Mail list logo