[R] strptime Usage

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Dec 1 08:45:49 CET 2003


On Mon, 1 Dec 2003, Ko-Kang Kevin Wang wrote:

> Thanks!
> 
> On Wed, 26 Nov 2003, Gabor Grothendieck wrote:
> 
> > Date: Wed, 26 Nov 2003 00:34:11 -0500 (EST)
> > From: Gabor Grothendieck <ggrothendieck at myway.com>
> > To: kwan022 at stat.auckland.ac.nz, r-help at stat.math.ethz.ch
> > Subject: RE: [R] strptime Usage
> > 
> > 
> > 
> > strptime takes a character input and produces a POSIXlt output so
> > the format you specify to strptime is the format of the input, 
> > not the output:
> > 
> >    format( strptime("10/22/1986", "%m/%d/%Y"), "%Y-%m" )
> 
> It worked perfect.  Just out of interest, if I want to convert (either 
> from the original form, i.e. mm/dd/yyyy, or the yyyy-mm form, to quarterly 
> format, e.g.:
>   1999-1
>   1999-2
>   1999-3
>   1999-4
> is it possible to do with strptime?  Or do I have to do something 
> creative? ;-D

Well, strptime converts from strings to internal date format, so it is 
logically impossible to do this with strptime.

As for quarters: how do you define them?  Does the quarters() function do 
what you want?  If almost, look at

> quarters.POSIXt
function (x, ...)
{
    x <- (as.POSIXlt(x)$mon)%/%3
    paste("Q", x + 1, sep = "")
}

for ideas.

-- 
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




More information about the R-help mailing list