[R] last day of month values

Joerg Maeder maeder at atmos.umnw.ethz.ch
Tue Feb 26 15:53:12 CET 2002


Hi Lukas

use the functions stpftime and strptime (see R documentation)
eg: as.numeric(strftime(f,format="%m")) for the months, year: "%y", day:
"%d"
Be carefull about leadings 0 (3 or 03) and try to write the year in 4
digits!
if your date is a string you can use as.numeric(substring(date,from,
length))
eg: month <- as.numeric(substring(date,4,2))


Lukas Kubin wrote:
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi Joerg,
> thank you for the answer, however I have the timestamp in format 26-02-02.
> Do I have to extract each part of the date?
> Thank you.
> 
> lukas
> 
> On Tue, 26 Feb 2002, Joerg Maeder wrote:
> 
> > Hallo Lukas,
> >
> > try this code
> > #data
> > d <-
> > data.frame(day=c(1,10,15,30,2,16,18,28),month=c(1,1,1,1,2,2,2,2),value=c(8,9,7,5,6,4,1,2))
> > #find the highest day per month
> > ma <- tapply(d$day,d$month,max)
> > #get them values
> > d$value[match(as.numeric(names(ma))+(ma-1)/31,d$month+(d$day-1)/31)]
> >
> > gruess
> >
> > joerg
> >
> > Lukas Kubin wrote:
> > >
> > > -----BEGIN PGP SIGNED MESSAGE-----
> > > Hash: SHA1
> > >
> > > I have a stock market trading values time series. What's the best way to
> > > extract the "last day of month" values. I looked at function window() but
> > > doesn't appear suitable for this since it expects regular dates.
> > > Thank you.
> > >
> > > lukas
> > >
> > > - --
> > > Lukas Kubin
> > > lukas.kubin at permonik.com
> > > phone: 00420603836180
> > > -----BEGIN PGP SIGNATURE-----
> > > Version: GnuPG v1.0.5 (GNU/Linux)
> > > Comment: For info see http://www.gnupg.org
> > >
> > > iD8DBQE8e2w74TIZ2lmUAtsRAj/SAJ4heMKveDwpCLPwnnJTBnAvCSIRrQCeJTHi
> > > YEujkKsmoX/orLUlnHxBNYA=
> > > =H9uw
> > > -----END PGP SIGNATURE-----
> > >
> > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> > > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> > > Send "info", "help", or "[un]subscribe"
> > > (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> > > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> >
> >
> 
> - --
> Lukas Kubin
> lukas.kubin at permonik.com
> phone: 00420603836180
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.5 (GNU/Linux)
> Comment: For info see http://www.gnupg.org
> 
> iD8DBQE8e5uJ4TIZ2lmUAtsRAuQXAKDCaNnEyXXVFa6fMS81klJIXDFrlgCgmm71
> zVnHeNICrNs6dvQd0Ir1YkI=
> =pcXi
> -----END PGP SIGNATURE-----

-- 
Joerg Maeder    .:|:||:..:.||.::   maeder at atmos.umnw.ethz.ch
Tel: +41 1 633 36 25   .:|:||:..:.||.::   
http://www.iac.ethz.ch/staff/maeder
PhD student at INSTITUTE FOR ATMOSPHERIC AND CLIMATE SCIENCE (IACETH)
ETH ZÜRICH Switzerland
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list