[R] Sort data by month

Zilefac Elvis zilefacelvis at yahoo.com
Thu May 23 06:32:46 CEST 2013


Hi Ak,
I seems to work correctly with your data. Please try it on my data (attached). My data is monthly.
The y in column 1 is not provided when I convert my data to zoo. 
So, delete the header, y and try to work with the data.
Sort all Jans, Febs, etc just as you did.
Atem.


________________________________
 From: arun <smartpink111 at yahoo.com>
To: Zilefac Elvis <zilefacelvis at yahoo.com> 
Cc: R help <r-help at r-project.org> 
Sent: Wednesday, May 22, 2013 8:47 PM
Subject: Re: [R] Sort data by month
 

Hi,
May be this helps.

date1<-seq.Date(as.Date("01/01/2000",format="%d/%m/%Y"),as.Date("31/12/2010",format="%d/%m/%Y"),by="day")
set.seed(24)
 value<- rnorm(4018,25)
 dat1<- data.frame(date1,value)
 dat2<- do.call(rbind,split(dat1,as.numeric(gsub(".*\\-(.*)\\-.*","\\1",dat1$date1))))

library(zoo)
z1<- as.zoo(dat2)

tail(z1,50)
     date1      value   
3969 2009-12-13 24.82354
3970 2009-12-14 25.01100
3971 2009-12-15 24.22370
3972 2009-12-16 26.20387
3973 2009-12-17 23.94170
3974 2009-12-18 24.39037
3975 2009-12-19 25.01231
3976 2009-12-20 25.25939
3977 2009-12-21 23.57236
3978 2009-12-22 26.42321
3979 2009-12-23 24.72704
3980 2009-12-24 24.60001
3981 2009-12-25 24.23091
3982 2009-12-26 23.63178
3983 2009-12-27 25.02472
3984 2009-12-28 25.58247
3985 2009-12-29 24.79180
3986 2009-12-30 24.93262
3987 2009-12-31 23.96313
3988 2010-12-01 25.83565
3989 2010-12-02 24.45985
3990 2010-12-03 25.17499
3991 2010-12-04 24.57330
3992 2010-12-05 24.52134
3993 2010-12-06 24.71778
3994 2010-12-07 25.81350
3995 2010-12-08 25.35647
3996 2010-12-09 24.50438
3997 2010-12-10 24.12099
3998 2010-12-11 25.16103
3999 2010-12-12 24.03809
4000 2010-12-13 24.31008
4001 2010-12-14 24.09804
4002 2010-12-15 25.58613
4003 2010-12-16 25.19094
4004 2010-12-17 25.75322
4005 2010-12-18 24.30318
4006 2010-12-19 24.79664
4007 2010-12-20 23.58302
4008 2010-12-21 24.37014
4009 2010-12-22 23.28147
4010 2010-12-23 23.70687
4011 2010-12-24 26.17041
4012 2010-12-25 24.76579
4013 2010-12-26 25.49849
4014 2010-12-27 23.64199
4015 2010-12-28 23.97338
4016 2010-12-29 24.96617
4017 2010-12-30 24.07872
4018 2010-12-31 25.25245
A.K.

----- Original Message -----
From: Zilefac Elvis <zilefacelvis at yahoo.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc: 
Sent: Wednesday, May 22, 2013 11:11 PM
Subject: [R] Sort data by month

Hello,
I have a 'zoo' object containing dates [dd/mm/yr] in the first column and values in the second column.
I tried as.Date but did not succeed.
Here is an example of date format
 01/01/2000

01/02/2000
...
01/12/2000
01/01/2001
01/02/2001

...
01/12/2000
  etc.
I would like to sort all Jans from 2000 to 2010, all Febs from 2000 to 2010 ... all Decs from 2000 to 2010.
So, basically I would like to sort by month.

Thanks for your help.
Atem.

    [[alternative HTML version deleted]]

______________________________________________
R-help at 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, self-contained, reproducible code.


More information about the R-help mailing list