[R] question about date's

Peter Dalgaard p.dalgaard at biostat.ku.dk
Mon Dec 12 15:02:28 CET 2005


Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:

> On Mon, 12 Dec 2005, ronggui wrote:
> 
> >> x<-as.Date(c("2005-07-01", "2005-07-02","2005-07-03","2005-07-04","2005-07-05"))
> >> weekdays(x)
> > [1] "ÐÇÆÚÎå" "ÐÇÆÚÁù" "ÐÇÆÚÈÕ" "ÐÇÆÚÒ»" "ÐÇÆÚ¶þ"
> >
> >> months(x)
> > [1] "ÆßÔÂ" "ÆßÔÂ" "ÆßÔÂ" "ÆßÔÂ" "ÆßÔÂ"
> 
> 
> He asked for week numbers.  That's nothing like as easy, as it is not
> well-defined.  But
> 
> > strftime(as.POSIXlt(x), "%U")
> [1] "26" "26" "27" "27" "27"
> 
> is one possibility ("%W" is another).  This approach will do the other
> requests just as easily.

%W seems to be what is known as "ISO dates" (week starts on Monday),
except that

>  strftime(as.POSIXlt(as.Date("2005-01-01")), "%U")
[1] "00"

should be week 53, 2004 according to my printed calendar, and emacs
calendar-mode too.


 
> > ======= 2005-12-12 20:17:38 ÄúÔÚÀ´ÐÅÖÐÐ´µÀ£º=======
> >
> >> Thanks!
> >> That solves my problem for year numbers and month numbers
> >> Any idea how to do this for week numbers?
> >>
> >> Regards,
> >> Richard
> >>
> >> On 12/12/05, ronggui <042045003 at fudan.edu.cn> wrote:
> >>> This is one way to do it.
> >>>> x<-c("2005-07-01", "2005-07-02","2005-07-03","2005-07-04","2005-07-05")
> >>>> x
> >>> [1] "2005-07-01" "2005-07-02" "2005-07-03" "2005-07-04" "2005-07-05"
> >>>> substr(x,1,4)
> >>> [1] "2005" "2005" "2005" "2005" "2005"
> >>>> substr(x,6,7)
> >>> [1] "07" "07" "07" "07" "07"
> >>>> substr(x,9,10)
> >>> [1] "01" "02" "03" "04" "05"
> >>>>
> >>>
> >>>
> >>> ======= 2005-12-12 20:06:00 ÄúÔÚÀ´ÐÅÖÐÐ´µÀ£º=======
> >>>
> >>>> Hi,
> >>>>
> >>>> Given a frame with calendar date's:
> >>>>
> >>>> "2005-07-01", "2005-07-02","2005-07-03","2005-07-04","2005-07-05",etc.
> >>>>
> >>>> I want to extract the following from these dates:
> >>>>
> >>>> week number
> >>>> month number
> >>>> year number
> >>>>
> >>>> Any ideas how to accomplish this?
> >>>>
> >>>> Many thanks.
> >>>>
> >>>> Regards,
> >>>> Richard
> >>>>
> >>>> ______________________________________________
> >>>> 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
> >>>
> >>> = = = = = = = = = = = = = = = = = = = =
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> 2005-12-12
> >>>
> >>> ------
> >>> Deparment of Sociology
> >>> Fudan University
> >>>
> >>> My new mail addres is ronggui.huang at gmail.com
> >>> Blog:http://sociology.yculblog.com
> >>>
> >
> > = = = = = = = = = = = = = = = = = = = =
> >
> >
> >
> >
> >
> > 2005-12-12
> >
> > ------
> > Deparment of Sociology
> > Fudan University
> >
> > My new mail addres is ronggui.huang at gmail.com
> > Blog:http://sociology.yculblog.com
> >
> >
> 
> -- 
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595______________________________________________
> 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

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list