Ted Byers
2009-Jan-27 16:36 UTC
[R] Can I create a timeDate object using only year and week of the year values?
For a model I am working on, I have samples organized by year and week of the year. For this model, the data (year and week) comes from the basic sample data, but I require a value representing the amount of time since the sample was taken (actually, for the purpose of the model, it is sufficient to use the number of weeks from the middle of the sample week to the present). What I have found so far includes: library(Rmetrics) time1 = timeDate(charvec = Sys.Date(), format = "%Y-%m-%d", zone = "", FinCenter = "") time2 = timeDate("2004-08-30", format = "%Y-%m-%d", zone = "", FinCenter "") difftimeDate(time1,time2,units = "weeks") Does timeDate use the format strings used by the UNIX date(1) command? If so, then can I safely assume timeDate will accept "%Y-%U-%w", and behave correctly? Thanks, Ted [[alternative HTML version deleted]]
Patrick Connolly
2009-Jan-27 19:03 UTC
[R] Can I create a timeDate object using only year and week of the year values?
On Tue, 27-Jan-2009 at 11:36AM -0500, Ted Byers wrote: [....] |> Does timeDate use the format strings used by the UNIX date(1) |> command? If so, then can I safely assume timeDate will accept |> "%Y-%U-%w", and behave correctly? Your chances are good. To be sure, check out ?strptime HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___ Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) ..... Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
Yohan Chalabi
2009-Jan-28 09:50 UTC
[R] Can I create a timeDate object using only year and week of the year values?
>>>> "TB" == Ted Byers <r.ted.byers at gmail.com> >>>> on Tue, 27 Jan 2009 11:36:22 -0500TB> What I have found so far includes: TB> TB> library(Rmetrics) TB> time1 = timeDate(charvec = Sys.Date(), format = %Y-%m-%d, TB> zone = , TB> FinCenter = ) TB> time2 = timeDate(2004-08-30, format = %Y-%m-%d, zone = , TB> FinCenter TB> ) TB> difftimeDate(time1,time2,units = weeks) TB> TB> TB> Does timeDate use the format strings used by the UNIX date(1) TB> command? If TB> so, then can I safely assume timeDate will accept %Y-%U-%w, TB> and behave TB> correctly? Hi Ted, timeDate uses internally the function 'strptime' to convert the input charvec to the ISO time format. As pointed out in the the manual page of 'strptime', the formats are system-specific but should follow the ISO C / POSIX standard. Have a look at ?strptime. Hope this help, Yohan -- PhD student Swiss Federal Institute of Technology Zurich www.ethz.ch