Date calculations

8 messages
Open this post in threaded view
|

Date calculations

 I'm a rank beginner in R and R-metrics, but experienced in matlab and other languages. I'm strugling with date arithmetics in R. I'm doing statistical analysis on financial time series, using its, which uses POSIXct objects to measure time. What is the best way to perform simple date arithmetic with these objects? I do not care about h/m/s, nor do I care about daylight saving time. Example of a problem I faced: Add one day to 3-apr-2005. (daylight saving starts on 4-apr-2005). If I do > as.POSIXct("2005-04-03") + 86400 I get 1 a.m. on the 4th of april. So, I do something like > dt1 <- as.POSIXct("2005-04-03") > x1 <- timeDate(dt1) > x2 <- timeNdayOnOrAfter(x1, n=2) > dt2 <- as.POSIXct(as.POSIXlt(x2)) There has to be something simpler! Another problem. The tseries and timeDate packages seem to require that one changes his timezone environment variable to GMT. This is not really possible in a corporate environment. Is there a work-around? Any help will be much appreciated. Patrick Henaff         [[alternative HTML version deleted]] _______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance
Open this post in threaded view
|

Re: Date calculations

Open this post in threaded view
|

Re: Date calculations

 In reply to this post by henaffp > I'm a rank beginner in R and R-metrics, but experienced in matlab and > other languages. I'm strugling with date arithmetics in R. I'm doing > statistical analysis on financial time series, using its, which uses > POSIXct objects to measure time. What is the best way to perform simple > date arithmetic with these objects? I do not care about h/m/s, nor do I > care about daylight saving time. Example of a problem I faced: Perhaps date() is what you want. That's what we use for financial applications in which h/m/s does not matter. Dave Kane _______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance
Open this post in threaded view
|

Re: Date calculations

 In reply to this post by henaffp On Wed, 22 Mar 2006 00:38:20 -0600 P. Hénaff wrote: > I'm a rank beginner in R and R-metrics, but experienced in matlab and > other languages. I'm strugling with date arithmetics in R. I'm doing > statistical analysis on financial time series, using its, which uses > POSIXct objects to measure time. What is the best way to perform > simple date arithmetic with these objects? I do not care about h/m/s, > nor do I care about daylight saving time. In that case I would recommend to go with the "Date" class available in base R, e.g.   as.Date("2005-04-03") + 0:10 which should be rather self-explanatory. The package zoo provides time series infrastructure where the time information can be stored in "Date" (or virtually any other class).   library("zoo")   z <- zoo(rnorm(11), as.Date("2005-04-03") + 0:10)   plot(z) hth, Z _______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance
Open this post in threaded view
|

Re: Date calculations

 In reply to this post by henaffp In addition to what's said already, I would just like to point out the very useful R Help Desk article "Date and Time classes in R" in R News June 2004 by Gabor Grothendieck and Thomas Petzoldt. >-----Original Message----- >From: [hidden email] >[mailto:[hidden email]] On Behalf Of >Achim Zeileis >Sent: 22 March 2006 02:19 PM >To: P. Hénaff" >Cc: [hidden email] >Subject: Re: [R-sig-finance] Date calculations > >On Wed, 22 Mar 2006 00:38:20 -0600 P. Hénaff wrote: > >> I'm a rank beginner in R and R-metrics, but experienced in >matlab and >> other languages. I'm strugling with date arithmetics in R. I'm doing >> statistical analysis on financial time series, using its, which uses >> POSIXct objects to measure time. What is the best way to perform >> simple date arithmetic with these objects? I do not care >about h/m/s, >> nor do I care about daylight saving time. > >In that case I would recommend to go with the "Date" class >available in base R, e.g. >  as.Date("2005-04-03") + 0:10 >which should be rather self-explanatory. > >The package zoo provides time series infrastructure where the >time information can be stored in "Date" (or virtually any >other class). >  library("zoo") >  z <- zoo(rnorm(11), as.Date("2005-04-03") + 0:10) >  plot(z) > >hth, >Z > >_______________________________________________ >[hidden email] mailing list >https://stat.ethz.ch/mailman/listinfo/r-sig-finance> ******************** Nedbank Limited Reg No 1951/000009/06. The following link displays the names of the Nedbank Board of Directors and Company Secretary. [ http://www.nedbank.co.za/terms/DirectorsNedbank.htm ] This email is confidential and is intended for the addressee only. The following link will take you to Nedbank's legal notice. [ http://www.nedbank.co.za/terms/EmailDisclaimer.htm ] ********************         [[alternative HTML version deleted]] _______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance
Open this post in threaded view
|